IDE : MSVS 2022, /std:c++latest, /experimental:module, x86 ;
Goal : to export T add(T,T) that requires std::integral<T> ;
This compiles (test.ixx) :
export module test;
template < typename T >
concept addable = requires ( T t1, T t2 ) {
t1 + t2 ;
};
export template < typename T >
requires addable<T>
T add ( T t1, T t2 ) { return t1 + t2; }
This does not (test.ixx) :
export module test;
#include <concepts>
export template < typename T >
requires std::integral<T>
T add ( T t1, T t2 ) { return t1 + t2; }
The above code causes 2 errors LNK2019, details below ;
Tried to
#include <concepts>in a separate implementation file - failed ;import std.core;, which seems to not yet be supported - failed ;
Usage sample (main.cpp) :
import test;
#include <iostream>
int main ()
{
using namespace std;
int i = add(22,20); // = 42
double d = add(0.5,0.77); // = 1.27
cout << i << ", " << d << endl ; // "42, 1.27"
return 0;
}
Any ideas ?
Linker error details :
LNK2019 : unresolved external symbol __imp__ldiv::<!test> referenced in function "struct test::_ldiv_t __cdecl div(long,long)" (?div@@YA?AU_ldiv_t@test@@JJ@Z::<!test>)
LNK2019 : unresolved external symbol __imp__lldiv::<!test> referenced in function "struct test::_lldiv_t __cdecl div(__int64,__int64)" (?div@@YA?AU_lldiv_t@test@@_J0@Z::<!test>)