這是我試過測試C++ - 概念功能的代碼。然而,即使在g ++ 6.2.0版本上使用標誌-fconcepts後,它似乎也不起作用。 任何幫助它得到它的工作將是偉大的!如何使用g ++ 6.2.0啓用概念?
#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));
}
這是我如何編譯:
g++-6 concepts.cpp -fconcepts
這是我的錯誤:
error: ‘RandomAccessIterator’ was not declared in this scope
我改變了拼寫random_access_iterator
,但它仍然無法正常工作。
6.2.13節中的文檔C++ Working Draft定義了RandomAccessIterator的存在。
您的概念RandomAccessIterator定義在哪裏? –
'RandomAccessIterator'不由標準庫提供。你需要定義它。 –
我應該如何定義它?什麼是確切的簽名? –