• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost enable_if library
2 
3 // Copyright 2003 (c) The Trustees of Indiana University.
4 
5 // Use, modification, and distribution is subject to the Boost Software
6 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 
9 //    Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
10 //             Jeremiah Willcock (jewillco at osl.iu.edu)
11 //             Andrew Lumsdaine (lums at osl.iu.edu)
12 
13 #include <boost/utility/enable_if.hpp>
14 #include <boost/type_traits/is_arithmetic.hpp>
15 #include <boost/core/lightweight_test.hpp>
16 
17 using boost::enable_if;
18 using boost::disable_if;
19 using boost::is_arithmetic;
20 
21 struct container {
22   template <class T>
23   typename enable_if<is_arithmetic<T>, bool>::type
arithmetic_objectcontainer24   arithmetic_object(const T&, const int* /* disambiguate */ = 0) {return true;}
25 
26   template <class T>
27   typename disable_if<is_arithmetic<T>, bool>::type
arithmetic_objectcontainer28   arithmetic_object(const T&) {return false;}
29 };
30 
main()31 int main()
32 {
33 
34   BOOST_TEST(container().arithmetic_object(1));
35   BOOST_TEST(container().arithmetic_object(1.0));
36 
37   BOOST_TEST(!container().arithmetic_object("1"));
38   BOOST_TEST(!container().arithmetic_object(static_cast<void*>(0)));
39 
40   return boost::report_errors();
41 }
42 
43