相关疑难解决方法(0)

什么是"表达SFINAE"?

http://blogs.msdn.com/b/vcblog/archive/2011/09/12/10209291.aspx上,VC++团队正式声明他们尚未实现C++ 11核心功能"Expression SFINAE".但是,从http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2634.html复制的以下代码示例将被VC++编译器接受.

例1:

template <int I> struct A {};

char xxx(int);
char xxx(float);

template <class T> A<sizeof(xxx((T)0))> f(T){}

int main()
{
    f(1);
}
Run Code Online (Sandbox Code Playgroud)

例2:

struct X {};
struct Y 
{
    Y(X){}
};

template <class T> auto f(T t1, T t2) -> decltype(t1 + t2); // #1
X f(Y, Y);  // #2

X x1, x2;
X x3 = f(x1, x2);  // deduction fails on #1 (cannot add X+X), calls #2
Run Code Online (Sandbox Code Playgroud)

我的问题是:什么是"表达SFINAE"?

c++ templates sfinae visual-c++ c++11

56
推荐指数
1
解决办法
1万
查看次数

type_traits使用std :: string进行分段错误

使用SFINAE收集信息以检查全局运算符<<?模板,decltype和非classtypes,我得到以下代码:

http://ideone.com/sEQc87

基本上我将两个问题的代码合并到调用print函数(如果它有ostream声明),或者调用to_string方法.

取自问题1

namespace has_insertion_operator_impl {
  typedef char no;
  typedef char yes[2];

  struct any_t {
    template<typename T> any_t( T const& );
  };

  no operator<<( std::ostream const&, any_t const& );

  yes& test( std::ostream& );
  no test( no );

  template<typename T>
  struct has_insertion_operator {
    static std::ostream &s;
    static T const &t;
    static bool const value = sizeof( test(s << t) ) == sizeof( yes );
  };
}

template<typename T> …
Run Code Online (Sandbox Code Playgroud)

c++ templates segmentation-fault sfinae

6
推荐指数
1
解决办法
351
查看次数

标签 统计

c++ ×2

sfinae ×2

templates ×2

c++11 ×1

segmentation-fault ×1

visual-c++ ×1