Die Vorlagen nicht teilweise auf C ++ 20 -Module spezialisiert habenC++

Programme in C++. Entwicklerforum
Anonymous
 Die Vorlagen nicht teilweise auf C ++ 20 -Module spezialisiert haben

Post by Anonymous »

Ich verwende Visual Studio 2026 Insider mit dem neuesten MSVC -Compiler und C ++ -
Der folgende Code kompiliert nicht: < /p>

Code: Select all

//Test.ixx
export module Test;
export import std;

export template
struct Foo {
size_t hash = 0;
};

namespace std {
template
struct hash {
using F = int;

size_t operator()(const Foo& f) const noexcept {
return hash{}(f.hash);
}
};
}

//main.cpp
import Test;

int main() {
std::unordered_map map; //multiple compiler errors
}
< /code>
Mit dem obigen Code erhalte ich die folgenden Compiler -Fehler: < /p>
std::_Hash::_Alnode: cannot access protected typedef declared in class std::_Hash` (unordered map, line 72)

see declaration of 'std::_Hash::_Alnode'
with
[
_Kty=Foo,
_Ty=std::string,
_Hasher=std::hash,
_Keyeq=std::equal_to,
_Alloc=std::allocator
] (xhash 330)

see declaration of 'std::_Hash'
with
[
_Kty=Foo,
_Ty=std::string,
_Hasher=std::hash,
_Keyeq=std::equal_to,
_Alloc=std::allocator
] (xhash 327)

see reference to class template instantiation 'std::unordered_map' being compiled (main.cpp 6)
Wenn ich diese nutzlose Zeile in main.cpp hinzufüge, wird der Code korrekt kompiliert:

Code: Select all

import Test;

int main()
{
std::hash::F; //new line
std::unordered_map map;
}
Ist dies nur ein Compiler -Fehler oder gibt es eine gewisse Interaktion mit Modulen und teilweisen Spezialisierungen, die ich einfach nicht verstehe?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post