使用在用于SFINAE的void_t中具有参数的方法
using methods with parameter(s) in void_t for SFINAE
我正在尝试构建一个结构is_container,以便在SFINAE模板上使用它
template<typename T, typename = void>
struct is_container : std::false_type {};
template<typename T>
struct is_container<
T,
std::void_t<
typename T::value_type,
typename T::reference,
typename T::const_reference,
typename T::iterator,
typename T::const_iterator,
typename T::difference_type,
typename T::size_type,
decltype(std::declval<T>().begin()),
decltype(std::declval<T>().end()),
decltype(std::declval<T>().cbegin()),
decltype(std::declval<T>().cend()) ,
decltype(std::declval<T>().size()),
decltype(std::declval<T>().max_size()),
decltype(std::declval<T>().empty()),
decltype(std::declval<T>().swap()) //<------ problem here
>
> : public std::true_type {};
template<typename T>
inline constexpr bool is_container_v = is_container<T>::value;
我的问题是交换函数需要一个T&参数,因此static_assert(is_container_v<vector<int>>(失败。他们是在我的void_t中使用带参数的方法的一种方式吗?
您已经使用过一次declval
来获取成员函数访问的内容。所以只要再次使用它来获得一个左值参数。
decltype(std::declval<T>().swap(std::declval<T&>()))
相关文章:
- c++方法参数只能在linux的发布模式下自行更改
- 使用移动语义:右值引用作为方法参数
- 无法将动态创建的对象数组从 qml 发送到 c++ 作为方法参数
- 将方法参数类型更改为子类中的派生类
- ofstream作为C 中的方法参数
- 使用 gmock 匹配器将 std::function 设置为 EXPECT_CALL 中的方法参数
- C com 方法参数扣除
- 获取非静态方法参数计数
- 使用 gmock 返回模拟方法参数
- 运行 QML 时出现"未知方法参数类型"错误
- 基本C - 构造contaning对象引用,并将其作为方法参数传递
- 将C 方法参数转换为模板参数会因编译错误而失败
- 如何在方法参数中使用boost :: asio :: buffer
- qsharedPointer作为方法参数或方法的返回值的良好实践
- 如何将方法指针声明为Typedef方法参数
- 方法参数中的 OpenCV 垫"预期")""
- 方法参数中的 consst* 常量
- 带有“class”详细类型说明符的方法参数
- 具有原始方法参数派生类的 C++ 重载方法参数
- C++ std::string length() 或 size() 不适用于方法参数