|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r48614 - in sandbox/type_traits: boost/type_traits boost/type_traits/detail libs/type_traits/test
From: frederic.bron_at_[hidden]
Date: 2008-09-05 11:24:05
Author: bronf
Date: 2008-09-05 11:24:04 EDT (Fri, 05 Sep 2008)
New Revision: 48614
URL: http://svn.boost.org/trac/boost/changeset/48614
Log:
Addition of new traits to know if a type is comparable or not. The names of the
traits are based on standard head <functional>: is_less_comparable,
is_less_equal_comparable... greater, greater_equal, equal_to, not_equal_to
Added:
sandbox/type_traits/boost/type_traits/detail/binary_op_traits.hpp (contents, props changed)
sandbox/type_traits/boost/type_traits/is_equal_to_comparable.hpp (contents, props changed)
sandbox/type_traits/boost/type_traits/is_greater_comparable.hpp (contents, props changed)
sandbox/type_traits/boost/type_traits/is_greater_equal_comparable.hpp (contents, props changed)
sandbox/type_traits/boost/type_traits/is_less_comparable.hpp (contents, props changed)
sandbox/type_traits/boost/type_traits/is_less_equal_comparable.hpp (contents, props changed)
sandbox/type_traits/boost/type_traits/is_not_equal_to_comparable.hpp (contents, props changed)
sandbox/type_traits/libs/type_traits/test/binary_op_traits_test.hpp (contents, props changed)
sandbox/type_traits/libs/type_traits/test/is_equal_to_comparable_test.cpp (contents, props changed)
sandbox/type_traits/libs/type_traits/test/is_greater_comparable_test.cpp (contents, props changed)
sandbox/type_traits/libs/type_traits/test/is_greater_equal_comparable_test.cpp (contents, props changed)
sandbox/type_traits/libs/type_traits/test/is_less_comparable_test.cpp (contents, props changed)
sandbox/type_traits/libs/type_traits/test/is_less_equal_comparable_test.cpp (contents, props changed)
sandbox/type_traits/libs/type_traits/test/is_not_equal_to_comparable_test.cpp (contents, props changed)
Added: sandbox/type_traits/boost/type_traits/detail/binary_op_traits.hpp
==============================================================================
--- (empty file)
+++ sandbox/type_traits/boost/type_traits/detail/binary_op_traits.hpp 2008-09-05 11:24:04 EDT (Fri, 05 Sep 2008)
@@ -0,0 +1,49 @@
+#include <boost/config.hpp>
+#include <boost/type_traits/remove_cv.hpp>
+#include <boost/type_traits/integral_constant.hpp>
+
+// should be the last #include
+#include <boost/type_traits/detail/bool_trait_def.hpp>
+
+namespace boost {
+namespace detail {
+
+// This namespace ensures that ADL doesn't mess things up.
+namespace BOOST_JOIN(BOOST_TT_TRAIT_NAME,_impl) {
+
+// a type returned from comparison operator when no such operator is found in the
+// type's own namespace
+struct tag { } ;
+
+// any soaks up implicit conversions and makes the following
+// comparison operators less-preferred than any other such operators that
+// might be found via ADL.
+struct any { template <class T> any(T const&) ; } ;
+
+tag operator BOOST_TT_TRAIT_OP (const any&, const any&) ;
+
+// In case a comparison operator is found that returns void, we'll use (x comp x),0
+tag operator,(tag, int) ;
+
+// two check overloads help us identify which comparison operator was picked
+
+// check(tag) returns a reference to char[2] (sizeof>1)
+char (& check(tag))[2] ;
+
+// check(not tag) returns char (sizeof==1)
+template <class T> char check(T const&) ;
+
+template <class T>
+struct BOOST_JOIN(BOOST_TT_TRAIT_NAME,_impl) {
+ static typename boost::remove_cv<T>::type &x ;
+ static const bool value = sizeof(check((x BOOST_TT_TRAIT_OP x, 0))) == 1 ;
+} ;
+
+} // namespace impl
+} // namespace detail
+
+BOOST_TT_AUX_BOOL_TRAIT_DEF1(BOOST_TT_TRAIT_NAME,T,::boost::detail::BOOST_JOIN(BOOST_TT_TRAIT_NAME,_impl)::BOOST_JOIN(BOOST_TT_TRAIT_NAME,_impl)<T>::value)
+
+} // namespace boost
+
+#include <boost/type_traits/detail/bool_trait_undef.hpp>
Added: sandbox/type_traits/boost/type_traits/is_equal_to_comparable.hpp
==============================================================================
--- (empty file)
+++ sandbox/type_traits/boost/type_traits/is_equal_to_comparable.hpp 2008-09-05 11:24:04 EDT (Fri, 05 Sep 2008)
@@ -0,0 +1,12 @@
+#ifndef BOOST_TT_IS_LESS_COMPARABLE_HPP_INCLUDED
+#define BOOST_TT_IS_LESS_COMPARABLE_HPP_INCLUDED
+
+#define BOOST_TT_TRAIT_NAME is_equal_to_comparable
+#define BOOST_TT_TRAIT_OP ==
+
+#include <boost/type_traits/detail/binary_op_traits.hpp>
+
+#undef BOOST_TT_TRAIT_NAME
+#undef BOOST_TT_TRAIT_OP
+
+#endif
Added: sandbox/type_traits/boost/type_traits/is_greater_comparable.hpp
==============================================================================
--- (empty file)
+++ sandbox/type_traits/boost/type_traits/is_greater_comparable.hpp 2008-09-05 11:24:04 EDT (Fri, 05 Sep 2008)
@@ -0,0 +1,12 @@
+#ifndef BOOST_TT_IS_LESS_COMPARABLE_HPP_INCLUDED
+#define BOOST_TT_IS_LESS_COMPARABLE_HPP_INCLUDED
+
+#define BOOST_TT_TRAIT_NAME is_greater_comparable
+#define BOOST_TT_TRAIT_OP >
+
+#include <boost/type_traits/detail/binary_op_traits.hpp>
+
+#undef BOOST_TT_TRAIT_NAME
+#undef BOOST_TT_TRAIT_OP
+
+#endif
Added: sandbox/type_traits/boost/type_traits/is_greater_equal_comparable.hpp
==============================================================================
--- (empty file)
+++ sandbox/type_traits/boost/type_traits/is_greater_equal_comparable.hpp 2008-09-05 11:24:04 EDT (Fri, 05 Sep 2008)
@@ -0,0 +1,12 @@
+#ifndef BOOST_TT_IS_LESS_COMPARABLE_HPP_INCLUDED
+#define BOOST_TT_IS_LESS_COMPARABLE_HPP_INCLUDED
+
+#define BOOST_TT_TRAIT_NAME is_greater_equal_comparable
+#define BOOST_TT_TRAIT_OP >=
+
+#include <boost/type_traits/detail/binary_op_traits.hpp>
+
+#undef BOOST_TT_TRAIT_NAME
+#undef BOOST_TT_TRAIT_OP
+
+#endif
Added: sandbox/type_traits/boost/type_traits/is_less_comparable.hpp
==============================================================================
--- (empty file)
+++ sandbox/type_traits/boost/type_traits/is_less_comparable.hpp 2008-09-05 11:24:04 EDT (Fri, 05 Sep 2008)
@@ -0,0 +1,12 @@
+#ifndef BOOST_TT_IS_LESS_COMPARABLE_HPP_INCLUDED
+#define BOOST_TT_IS_LESS_COMPARABLE_HPP_INCLUDED
+
+#define BOOST_TT_TRAIT_NAME is_less_comparable
+#define BOOST_TT_TRAIT_OP <
+
+#include <boost/type_traits/detail/binary_op_traits.hpp>
+
+#undef BOOST_TT_TRAIT_NAME
+#undef BOOST_TT_TRAIT_OP
+
+#endif
Added: sandbox/type_traits/boost/type_traits/is_less_equal_comparable.hpp
==============================================================================
--- (empty file)
+++ sandbox/type_traits/boost/type_traits/is_less_equal_comparable.hpp 2008-09-05 11:24:04 EDT (Fri, 05 Sep 2008)
@@ -0,0 +1,12 @@
+#ifndef BOOST_TT_IS_LESS_COMPARABLE_HPP_INCLUDED
+#define BOOST_TT_IS_LESS_COMPARABLE_HPP_INCLUDED
+
+#define BOOST_TT_TRAIT_NAME is_less_equal_comparable
+#define BOOST_TT_TRAIT_OP <=
+
+#include <boost/type_traits/detail/binary_op_traits.hpp>
+
+#undef BOOST_TT_TRAIT_NAME
+#undef BOOST_TT_TRAIT_OP
+
+#endif
Added: sandbox/type_traits/boost/type_traits/is_not_equal_to_comparable.hpp
==============================================================================
--- (empty file)
+++ sandbox/type_traits/boost/type_traits/is_not_equal_to_comparable.hpp 2008-09-05 11:24:04 EDT (Fri, 05 Sep 2008)
@@ -0,0 +1,12 @@
+#ifndef BOOST_TT_IS_LESS_COMPARABLE_HPP_INCLUDED
+#define BOOST_TT_IS_LESS_COMPARABLE_HPP_INCLUDED
+
+#define BOOST_TT_TRAIT_NAME is_not_equal_to_comparable
+#define BOOST_TT_TRAIT_OP !=
+
+#include <boost/type_traits/detail/binary_op_traits.hpp>
+
+#undef BOOST_TT_TRAIT_NAME
+#undef BOOST_TT_TRAIT_OP
+
+#endif
Added: sandbox/type_traits/libs/type_traits/test/binary_op_traits_test.hpp
==============================================================================
--- (empty file)
+++ sandbox/type_traits/libs/type_traits/test/binary_op_traits_test.hpp 2008-09-05 11:24:04 EDT (Fri, 05 Sep 2008)
@@ -0,0 +1,74 @@
+// (C) Copyright Frederic Bron 2008.
+// 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 <iostream>
+#include <typeinfo>
+#include <string>
+#include <vector>
+
+namespace BOOST_JOIN(BOOST_TT_TRAIT_NAME,_test) {
+
+class Base1 { } ;
+class Derived1 : public Base1 { } ;
+
+bool operator BOOST_TT_TRAIT_OP (const Base1&, const Base1&) { return true ; }
+
+class Base2 { } ;
+struct Derived2 : public Base2 {
+ Derived2(int) ; // to check if it works with a class that is not default constructible
+} ;
+
+bool operator BOOST_TT_TRAIT_OP (const Derived2&, const Derived2&) { return true ; }
+
+class Without { } ;
+
+struct member_comparable {
+ bool operator BOOST_TT_TRAIT_OP (const member_comparable&) const ;
+} ;
+
+struct returns_void { } ;
+void operator BOOST_TT_TRAIT_OP (const returns_void&, const returns_void&) ;
+
+struct returns_void_star { } ;
+void* operator BOOST_TT_TRAIT_OP (const returns_void_star&, const returns_void_star&) ;
+
+struct returns_double { } ;
+double operator BOOST_TT_TRAIT_OP (const returns_double&, const returns_double&) ;
+
+struct returns_string { } ;
+std::string operator BOOST_TT_TRAIT_OP (const returns_string&, const returns_string&) ;
+
+}
+
+TT_TEST_BEGIN(BOOST_TT_TRAIT_NAME)
+
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<bool>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<char>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<signed char>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<unsigned char>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<wchar_t>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<signed wchar_t>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<unsigned wchar_t>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<short>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<unsigned short>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<int>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<unsigned int>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<long>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<unsigned long>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<float>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<double>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<std::string>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<BOOST_JOIN(BOOST_TT_TRAIT_NAME,_test)::Base1>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<BOOST_JOIN(BOOST_TT_TRAIT_NAME,_test)::Derived1>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<BOOST_JOIN(BOOST_TT_TRAIT_NAME,_test)::Base2>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<BOOST_JOIN(BOOST_TT_TRAIT_NAME,_test)::Derived2>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<BOOST_JOIN(BOOST_TT_TRAIT_NAME,_test)::Without>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<BOOST_JOIN(BOOST_TT_TRAIT_NAME,_test)::member_comparable>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<BOOST_JOIN(BOOST_TT_TRAIT_NAME,_test)::returns_void>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<BOOST_JOIN(BOOST_TT_TRAIT_NAME,_test)::returns_void_star>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<BOOST_JOIN(BOOST_TT_TRAIT_NAME,_test)::returns_double>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::BOOST_TT_TRAIT_NAME<BOOST_JOIN(BOOST_TT_TRAIT_NAME,_test)::returns_string>::value, true);
+
+TT_TEST_END
Added: sandbox/type_traits/libs/type_traits/test/is_equal_to_comparable_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/type_traits/libs/type_traits/test/is_equal_to_comparable_test.cpp 2008-09-05 11:24:04 EDT (Fri, 05 Sep 2008)
@@ -0,0 +1,17 @@
+// (C) Copyright Frederic Bron 2008.
+// 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 "test.hpp"
+#include "check_integral_constant.hpp"
+#ifdef TEST_STD
+# include <type_traits>
+#else
+# include <boost/type_traits/is_equal_to_comparable.hpp>
+#endif
+
+#define BOOST_TT_TRAIT_NAME is_equal_to_comparable
+#define BOOST_TT_TRAIT_OP ==
+
+#include "binary_op_traits_test.hpp"
Added: sandbox/type_traits/libs/type_traits/test/is_greater_comparable_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/type_traits/libs/type_traits/test/is_greater_comparable_test.cpp 2008-09-05 11:24:04 EDT (Fri, 05 Sep 2008)
@@ -0,0 +1,17 @@
+// (C) Copyright Frederic Bron 2008.
+// 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 "test.hpp"
+#include "check_integral_constant.hpp"
+#ifdef TEST_STD
+# include <type_traits>
+#else
+# include <boost/type_traits/is_greater_comparable.hpp>
+#endif
+
+#define BOOST_TT_TRAIT_NAME is_greater_comparable
+#define BOOST_TT_TRAIT_OP >
+
+#include "binary_op_traits_test.hpp"
Added: sandbox/type_traits/libs/type_traits/test/is_greater_equal_comparable_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/type_traits/libs/type_traits/test/is_greater_equal_comparable_test.cpp 2008-09-05 11:24:04 EDT (Fri, 05 Sep 2008)
@@ -0,0 +1,17 @@
+// (C) Copyright Frederic Bron 2008.
+// 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 "test.hpp"
+#include "check_integral_constant.hpp"
+#ifdef TEST_STD
+# include <type_traits>
+#else
+# include <boost/type_traits/is_greater_equal_comparable.hpp>
+#endif
+
+#define BOOST_TT_TRAIT_NAME is_greater_equal_comparable
+#define BOOST_TT_TRAIT_OP >=
+
+#include "binary_op_traits_test.hpp"
Added: sandbox/type_traits/libs/type_traits/test/is_less_comparable_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/type_traits/libs/type_traits/test/is_less_comparable_test.cpp 2008-09-05 11:24:04 EDT (Fri, 05 Sep 2008)
@@ -0,0 +1,17 @@
+// (C) Copyright Frederic Bron 2008.
+// 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 "test.hpp"
+#include "check_integral_constant.hpp"
+#ifdef TEST_STD
+# include <type_traits>
+#else
+# include <boost/type_traits/is_less_comparable.hpp>
+#endif
+
+#define BOOST_TT_TRAIT_NAME is_less_comparable
+#define BOOST_TT_TRAIT_OP <
+
+#include "binary_op_traits_test.hpp"
Added: sandbox/type_traits/libs/type_traits/test/is_less_equal_comparable_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/type_traits/libs/type_traits/test/is_less_equal_comparable_test.cpp 2008-09-05 11:24:04 EDT (Fri, 05 Sep 2008)
@@ -0,0 +1,17 @@
+// (C) Copyright Frederic Bron 2008.
+// 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 "test.hpp"
+#include "check_integral_constant.hpp"
+#ifdef TEST_STD
+# include <type_traits>
+#else
+# include <boost/type_traits/is_less_equal_comparable.hpp>
+#endif
+
+#define BOOST_TT_TRAIT_NAME is_less_equal_comparable
+#define BOOST_TT_TRAIT_OP <=
+
+#include "binary_op_traits_test.hpp"
Added: sandbox/type_traits/libs/type_traits/test/is_not_equal_to_comparable_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/type_traits/libs/type_traits/test/is_not_equal_to_comparable_test.cpp 2008-09-05 11:24:04 EDT (Fri, 05 Sep 2008)
@@ -0,0 +1,17 @@
+// (C) Copyright Frederic Bron 2008.
+// 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 "test.hpp"
+#include "check_integral_constant.hpp"
+#ifdef TEST_STD
+# include <type_traits>
+#else
+# include <boost/type_traits/is_not_equal_to_comparable.hpp>
+#endif
+
+#define BOOST_TT_TRAIT_NAME is_not_equal_to_comparable
+#define BOOST_TT_TRAIT_OP !=
+
+#include "binary_op_traits_test.hpp"
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