Reputation: 433
Here is a code I've tried out to test the c++-concepts feature. However it does not seem to work even after using the flag -fconcepts on g++ 6.2.0 version. Any help to get it working would be great!
#include <iostream>
using namespace std;
#include <list>
#include <vector>
#include <algorithm>
#include <iterator>
#include <bits/stdc++.h>
using namespace std::literals;
template<typename ptr_t >
requires RandomAccessIterator<ptr_t>
void mysort(ptr_t first, ptr_t last)
{
sort(first, last);
}
int main()
{
vector<int> v{22, 11, 55, 33, 44};
list<int> l{22, 11, 55, 33, 44};
mysort(begin(v), end(v));
mysort(begin(l), end(l));
}
This is how I compile it:
g++-6 concepts.cpp -fconcepts
This is the error I get:
error: ‘RandomAccessIterator’ was not declared in this scope
I changed the spelling to random_access_iterator
but it still does not work.
The document C++ Working Draft in section 6.2.13 defines the presence of RandomAccessIterator.
Upvotes: 2
Views: 1056
Reputation: 93304
RandomAccessIterator
is not (yet) provided by the Standard Library. You need to define it.
The relevant documentation on cppreference is a good place to get started with the concept's requirements.
The document you linked, N4620, is the working draft for Ranges, not for Concepts. Unless you include an implementation of ranges that is -fconcepts
friendly you will not get RandomAccessIterator
defined for you.
As Tristan Brindle mentioned in his answer, cmcstl2
is the reference implementation for the Ranges TS.
Upvotes: 5
Reputation: 16824
The Concepts TS doesn't actually include any standard concepts such as RandomAccessIterator
. These are being worked on in a separate Ranges TS.
The reference implementation of the Ranges TS is available at https://github.com/CaseyCarter/cmcstl2.
Upvotes: 1