Consider the following code:
#include <iostream>
#include <utility>
#include <type_traits>
using namespace std;
template<typename K>
requires is_nothrow_move_constructible<K>::value
struct S
{
using value_type = pair<K, K>;
struct iterator
{
};
template<typename P>
requires is_constructible<value_type, P &&>::value
pair<iterator, bool> insert( P &&x );
};
template<typename K>
requires is_nothrow_move_constructible<K>::value
template<typename P>
requires is_constructible<typename S<K>::value_type, P &&>::value
pair<typename S<K>::iterator, bool> S<K>::insert( P &&x )
{
}
int main()
{
std::cout << "Hello World!\n";
}
Why does this compile with g++ 11.1.0 and not with clang 12.0.0. The clang-error is:
xxx.cpp:24:43: error: out-of-line definition of 'insert' does not match any declaration in 'S<K>'
pair<typename S<K>::iterator, bool> S<K>::insert( P &&x )
^~~~~~
1 error generated.
clang++ 13.0.0 under Windows does report the same error.
MSVC 19.29.30136 gives the following error:
xxx.cpp
xxx.cpp(25): error C2244: 'S<K>::insert': unable to match function definition to an existing declaration
xxx.cpp(24): note: see declaration of 'S<K>::insert'
xxx.cpp(25): note: definition
xxx.cpp(25): note: 'std::pair<S<K>::iterator,bool> S<K>::insert(P &&)'
xxx.cpp(25): note: existing declarations
xxx.cpp(25): note: 'std::pair<S<K>::iterator,bool> S<K>::insert(P &&)'
Is there a workaround ?