typetraits

    5热度

    3回答

    我有下面的代码段,其中我定义struct quick与模板static方法random一些专业:(。我使用来自其他function_traits SO回答附于底部供参考) struct quick { template <typename T> static T random(); template <typename F> static void ch

    1热度

    1回答

    我刚刚遇到std::rank,我不太明白它可以用于什么。我明白它的作用,但有人可以给我几个用例吗?我在这里找不到有用的东西。

    1热度

    2回答

    我想编写函数模板一样 template< typename T > void foo(T& obj){ obj[0] = xxxxxx; } 其中T必须具有操作员[]适用。 T可以是任何类型的数组,std :: vector,std :: array或任何其他类型。所以,我不能用T作为他们所有人的超类。我认为这应该是在std::type_traits风格。

    4热度

    1回答

    我想在C++ 11(msvc2013)中编写一个类型特征,这将允许我检查函数类型是否需要某些参数。我不要希望它检查返回类型。我认为这个想法基本上等于std::is_callable,但我很想知道我的方法有什么问题,除了如何真正解决问题。 我的实现: namespace traits { namespace detail { template <typename T

    0热度

    1回答

    我现在正在学习如何使用boost::geometry库,并且我正在学习教程,其中引入了类型特征以使代码更通用。 struct mypoint { double x, y; }; template <typename P1, typename P2> double distance(P1 const& a, P2 const& b) { double dx = get

    2热度

    1回答

    考虑下面的代码: #include <iostream> #include <type_traits> int main() { std::aligned_storage<sizeof(double), alignof(double)> storage; std::aligned_union<sizeof(double), double> union_storage;

    0热度

    1回答

    以下代码来自示例代码,以说明如何使用boost :: type_traits。它将使用两种方法交换两个变量。很容易理解,当两个变量是整数(int)时,它们的类型特征对应于true_type。但是,当两个变量是布尔类型时,它们不再被视为true_type。为什么会发生?谢谢。 #include <iostream> #include <typeinfo> #include <algorithm>

    1热度

    1回答

    可以假设在未评估的上下文中,(::new (std::declval< void * >()) T())->~T()在语义上(在noexcept的意义上,但不是在表达类型意义上)等价于简单T()?假设全球性的,也不是类范围operator new超载,如果它喃喃自语。 通常在类型特征T()内部运算符noexcept()中用于确定是否只有单独的构造函数是否为noexcept。这当然是错误的。 为了防

    1热度

    4回答

    ​​ 上面会输出的程序: 1 0 它显示了模板has_push_back如果函数push_back继承不起作用。 即使它被继承,是否有办法让它工作?

    4热度

    1回答

    我玩弄type_traits,我发现了这个奇怪的std::string属性: $ cat a.cpp #include <string> #include <type_traits> static_assert(std::is_nothrow_move_assignable<std::string>::value, "???"); static_assert(noexcept(std::