optional_deduced_sfinae.cpp
来自「Boost provides free peer-reviewed portab」· C++ 代码 · 共 74 行
CPP
74 行
// Copyright Daniel Wallin 2006. Use, modification and distribution is// subject to the Boost Software License, Version 1.0. (See accompanying// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)#include <boost/parameter/preprocessor.hpp>#include <boost/parameter/name.hpp>#include <boost/type_traits/is_convertible.hpp>#include <boost/tuple/tuple.hpp>#include <string>#include "basics.hpp"#include <boost/utility/enable_if.hpp>namespace test {namespace mpl = boost::mpl;using mpl::_;using boost::is_convertible;BOOST_PARAMETER_NAME(x)// Sun has problems with this syntax://// template1< r* ( template2<x> ) >//// Workaround: factor template2<x> into a separate typedef#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580))typedef is_convertible<_,char const*> predicate;BOOST_PARAMETER_FUNCTION((int), sfinae, tag, (deduced (optional (x, *(predicate), 0)) )){ return 1;}#elseBOOST_PARAMETER_FUNCTION((int), sfinae, tag, (deduced (optional (x, *(is_convertible<_,char const*>), 0)) )){ return 1;}#endiftemplate<class A0>typename boost::enable_if<boost::is_same<int,A0>, int>::typesfinae(A0 const& a0){ return 0;}} // namespace testint main(){ using namespace test; assert(sfinae() == 1); assert(sfinae("foo") == 1); assert(sfinae(1) == 0); return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?