Код: Выделить всё
template
struct CollectIntoAllocatedContainer
{
// ...
};
template
struct CollectIntoAllocatedContainerWithCharTraits
{
// ...
};
template
constexpr CollectIntoAllocatedContainer collect()
{
return {};
}
template
constexpr CollectIntoAllocatedContainerWithCharTraits collect()
{
return {};
}
int main() {
collect().dosomething();
collect().dosomething();
}
Код: Выделить всё
error: call of overloaded ‘collect()’ is ambiguous
78 | collect();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~^~
note: candidate: ‘constexpr CollectIntoAllocatedContainer collect() [with T = std::__cxx11::basic_string]’
64 | constexpr CollectIntoAllocatedContainer collect()
| ^~~~~~~
note: candidate: ‘constexpr CollectIntoAllocatedContainerWithCharTraits collect() [with T = std::__cxx11::basic_string]’
70 | constexpr CollectIntoAllocatedContainerWithCharTraits collect()
| ^~~~~~~
Код: Выделить всё
template
concept AllocatedContainer = requires(V x) {
typename T;
};
template
concept AllocatedContainerWithCharTraits = requires(V x) {
typename T;
};
template
constexpr CollectIntoAllocatedContainer collect()
requires AllocatedContainer
{
return {};
}
template
constexpr CollectIntoAllocatedContainerWithCharTraits collect()
requires AllocatedContainerWithCharTraits
{
return {};
}
Я использую:
- gcc 13.3.0
- clang 17.0.2 (android, Armv7, ndk: 26.1.10909125)
P.S: Я не могу менять версии компиляторов, так как они привязаны к корпоративной инфраструктуре моей компании.
Подробнее здесь: https://stackoverflow.com/questions/793 ... -using-gcc
Мобильная версия