Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85396 - sandbox/enable_if/libs/enable_if/test
From: rivorus_at_[hidden]
Date: 2013-08-19 12:21:20


Author: matt_calabrese
Date: 2013-08-19 12:21:19 EDT (Mon, 19 Aug 2013)
New Revision: 85396
URL: http://svn.boost.org/trac/boost/changeset/85396

Log:
Added type validity tests.

Added:
   sandbox/enable_if/libs/enable_if/test/enable_if_valid_type.cpp (contents, props changed)
   sandbox/enable_if/libs/enable_if/test/lazy_enable_if_valid_type.cpp (contents, props changed)
   sandbox/enable_if/libs/enable_if/test/type_enable_if_valid_type.cpp (contents, props changed)
Text files modified:
   sandbox/enable_if/libs/enable_if/test/Jamfile | 3 ++
   sandbox/enable_if/libs/enable_if/test/enable_if_valid_type.cpp | 34 ++++++++++++++++++++++++++++++
   sandbox/enable_if/libs/enable_if/test/lazy_enable_if_valid_type.cpp | 45 ++++++++++++++++++++++++++++++++++++++++
   sandbox/enable_if/libs/enable_if/test/type_enable_if_valid_type.cpp | 39 ++++++++++++++++++++++++++++++++++
   4 files changed, 121 insertions(+), 0 deletions(-)

Modified: sandbox/enable_if/libs/enable_if/test/Jamfile
==============================================================================
--- sandbox/enable_if/libs/enable_if/test/Jamfile Mon Aug 19 12:19:14 2013 (r85395)
+++ sandbox/enable_if/libs/enable_if/test/Jamfile 2013-08-19 12:21:19 EDT (Mon, 19 Aug 2013) (r85396)
@@ -25,18 +25,21 @@
     [ compile enable_if_c.cpp : : : : ]
     [ compile enable_if_expr.cpp : : : : ]
     [ compile enable_if_expr_seq.cpp : : : : ]
+ [ compile enable_if_valid_type.cpp : : : : ]
     [ compile lazy_disable_if.cpp : : : : ]
     [ compile lazy_disable_if_c.cpp : : : : ]
     [ compile lazy_enable_if.cpp : : : : ]
     [ compile lazy_enable_if_c.cpp : : : : ]
     [ compile lazy_enable_if_expr.cpp : : : : ]
     [ compile lazy_enable_if_expr_seq.cpp : : : : ]
+ [ compile lazy_enable_if_valid_type.cpp : : : : ]
     [ compile type_disable_if.cpp : : : : ]
     [ compile type_disable_if_c.cpp : : : : ]
     [ compile type_enable_if.cpp : : : : ]
     [ compile type_enable_if_c.cpp : : : : ]
     [ compile type_enable_if_expr.cpp : : : : ]
     [ compile type_enable_if_expr_seq.cpp : : : : ]
+ [ compile type_enable_if_valid_type.cpp : : : : ]
 
     ;
 }

Added: sandbox/enable_if/libs/enable_if/test/enable_if_valid_type.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ sandbox/enable_if/libs/enable_if/test/enable_if_valid_type.cpp 2013-08-19 12:21:19 EDT (Mon, 19 Aug 2013) (r85396)
@@ -0,0 +1,34 @@
+/*==============================================================================
+ Copyright (c) 2012 Matt Calabrese
+
+ Use modification and distribution are 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/utility/enable_if_macros.hpp>
+
+#include <boost/mpl/bool.hpp>
+#include <utility>
+
+boost::mpl::false_ has_nested_result_type( ... );
+
+template< class T
+ , BOOST_ENABLE_IF_VALID_TYPE( typename T::result_type )
+ >
+boost::mpl::true_ has_nested_result_type( T );
+
+struct nested_result_type_t
+{
+ typedef void result_type;
+};
+
+static_assert( !decltype( has_nested_result_type( 1 ) )::value
+ , "int incorrectly detected as having a nested result type."
+ );
+
+static_assert
+( decltype( has_nested_result_type( nested_result_type_t() ) )::value
+, "nested_result_type_t incorrectly detected as not having a "
+ "nested result type."
+);

Added: sandbox/enable_if/libs/enable_if/test/lazy_enable_if_valid_type.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ sandbox/enable_if/libs/enable_if/test/lazy_enable_if_valid_type.cpp 2013-08-19 12:21:19 EDT (Mon, 19 Aug 2013) (r85396)
@@ -0,0 +1,45 @@
+/*==============================================================================
+ Copyright (c) 2012 Matt Calabrese
+
+ Use modification and distribution are 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/utility/enable_if_macros.hpp>
+
+#include <boost/mpl/bool.hpp>
+#include <utility>
+
+boost::mpl::false_ has_nested_result_type( ... );
+
+template< class T >
+struct error_if_no_nested_result_type
+ : boost::mpl::true_
+{
+ typedef typename T::result_type error_if_result_type_does_not_exist;
+};
+
+template< class T
+ , BOOST_LAZY_ENABLE_IF_VALID_TYPE
+ ( typename T::result_type
+ , ( ResultType, typename error_if_no_nested_result_type< T >::type )
+ , ( DefaultParamType, ResultType )
+ )
+ >
+ResultType has_nested_result_type( T, DefaultParamType = DefaultParamType() );
+
+struct nested_result_type_t
+{
+ typedef void result_type;
+};
+
+static_assert( !decltype( has_nested_result_type( 1 ) )::value
+ , "int incorrectly detected as having a nested result type."
+ );
+
+static_assert
+( decltype( has_nested_result_type( nested_result_type_t() ) )::value
+, "nested_result_type_t incorrectly detected as not having a "
+ "nested result type."
+);

Added: sandbox/enable_if/libs/enable_if/test/type_enable_if_valid_type.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ sandbox/enable_if/libs/enable_if/test/type_enable_if_valid_type.cpp 2013-08-19 12:21:19 EDT (Mon, 19 Aug 2013) (r85396)
@@ -0,0 +1,39 @@
+/*==============================================================================
+ Copyright (c) 2012 Matt Calabrese
+
+ Use modification and distribution are 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/utility/enable_if_macros.hpp>
+
+#include <boost/mpl/bool.hpp>
+#include <utility>
+
+template< class T, BOOST_DECLARE_ENABLE_IF_PARAM() >
+struct has_nested_result_type : boost::mpl::false_ {};
+
+template< class T >
+struct has_nested_result_type
+ < T
+ , BOOST_TYPE_ENABLE_IF_VALID_TYPE( typename T::result_type )
+ > : boost::mpl::true_ {};
+
+struct nested_result_type_t
+{
+ typedef void result_type;
+};
+
+static_assert( !has_nested_result_type< void >::value
+ , "void incorrectly detected as having a nested result type."
+ );
+
+static_assert( !has_nested_result_type< int >::value
+ , "int incorrectly detected as having a nested result type."
+ );
+
+static_assert( has_nested_result_type< nested_result_type_t >::value
+ , "nested_result_type_t incorrectly detected as not having a "
+ "nested result type."
+ );


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk