c++-concepts

Use of 'auto […] 'before deduction of 'auto' with recursive, concept-based function template

荒凉一梦 提交于 2020-12-25 03:48:06
问题 I wanted to create a deep_flatten function template that would produce a range of elements that are deeply join ed. For example, if we take into account only nested std::vector s, I can have: template <typename T> struct is_vector : public std::false_type { }; template <typename T, typename A> struct is_vector<std::vector<T, A>> : public std::true_type { }; template <typename T> auto deepFlatten(const std::vector<std::vector<T>>& vec) { using namespace std::ranges; if constexpr (is_vector<T>:

Why isn't this class specialization using a concept accepted?

▼魔方 西西 提交于 2020-11-29 08:58:09
问题 The following code attempts to partially specialize a class using a concept and add a method to the specialization, but it is rejected by clang 11.0.0: #include <concepts> template <typename T> // note: previous template declaration is here struct S {}; template <std::integral T> struct S<T> { void f(); }; template <std::integral T> // error: type constraint differs in template redeclaration void S<T>::f() { } clang gives the error message: <source>:14:16: error: type constraint differs in