Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r76691 - sandbox/local_function/libs/utility/identity_type/test
From: lorcaminiti_at_[hidden]
Date: 2012-01-25 16:43:45


Author: lcaminiti
Date: 2012-01-25 16:43:43 EST (Wed, 25 Jan 2012)
New Revision: 76691
URL: http://svn.boost.org/trac/boost/changeset/76691

Log:
Tests.
Added:
   sandbox/local_function/libs/utility/identity_type/test/Jamfile.v2 (contents, props changed)
   sandbox/local_function/libs/utility/identity_type/test/template.cpp (contents, props changed)
   sandbox/local_function/libs/utility/identity_type/test/tmp_assert.cpp (contents, props changed)
Properties modified:
   sandbox/local_function/libs/utility/identity_type/test/ (props changed)
Text files modified:
   sandbox/local_function/libs/utility/identity_type/test/var_err.cpp | 8 ++++----
   sandbox/local_function/libs/utility/identity_type/test/var_ok.cpp | 13 +++++++++----
   2 files changed, 13 insertions(+), 8 deletions(-)

Added: sandbox/local_function/libs/utility/identity_type/test/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/local_function/libs/utility/identity_type/test/Jamfile.v2 2012-01-25 16:43:43 EST (Wed, 25 Jan 2012)
@@ -0,0 +1,8 @@
+
+import testing ;
+
+compile-fail var_err.cpp ;
+run var_ok.cpp ;
+run template.cpp ;
+run tmp_assert.cpp ;
+

Added: sandbox/local_function/libs/utility/identity_type/test/template.cpp
==============================================================================
--- (empty file)
+++ sandbox/local_function/libs/utility/identity_type/test/template.cpp 2012-01-25 16:43:43 EST (Wed, 25 Jan 2012)
@@ -0,0 +1,42 @@
+
+#include <boost/utility/identity_type.hpp>
+#include <map>
+#include <iostream>
+
+//[template_f_decl
+#define ARG(type, n) type arg ## n
+
+template<typename T>
+void f( // Prefix macro with `typename` in templates.
+ ARG( typename BOOST_IDENTITY_TYPE((std::map<int, T>)), 1 )
+) {
+ std::cout << arg1[0] << std::endl;
+}
+//]
+
+//[template_g_decl
+template<typename T>
+void g(
+ std::map<int, T> arg1
+) {
+ std::cout << arg1[0] << std::endl;
+}
+//]
+
+int main() {
+ //[template_f_call
+ std::map<int, char> a;
+ a[0] = 'a';
+
+ f<char>(a); // OK.
+ // f(a); // But error.
+ //]
+
+ //[template_g_call
+ g<char>(a); // OK.
+ g(a); // Also OK.
+ //]
+
+ return 0;
+}
+

Added: sandbox/local_function/libs/utility/identity_type/test/tmp_assert.cpp
==============================================================================
--- (empty file)
+++ sandbox/local_function/libs/utility/identity_type/test/tmp_assert.cpp 2012-01-25 16:43:43 EST (Wed, 25 Jan 2012)
@@ -0,0 +1,45 @@
+
+#include <boost/utility/identity_type.hpp>
+#include <boost/type_traits/is_const.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/type_traits/add_reference.hpp>
+#include <boost/type_traits/remove_reference.hpp>
+#include <map>
+
+//[tmp_assert_abstract
+#define TMP_ASSERT(metafunction) \
+ BOOST_STATIC_ASSERT(metafunction::value)
+
+template<typename T, bool b>
+struct abstract {
+ static const bool value = b;
+ virtual void f(T const& x) = 0;
+};
+
+TMP_ASSERT(
+ boost::remove_reference< // Add and remove
+ BOOST_IDENTITY_TYPE(( // reference for
+ boost::add_reference< // abstract type.
+ abstract<int, true>
+ >::type
+ ))
+ >::type
+);
+//]
+
+//[tmp_assert_alternative
+#define TMP_ASSERT_PAREN(parenthesized_metafunction) \
+ /* use `BOOST_IDENTITY_TYPE` in macro definition instead of invocation */ \
+ BOOST_STATIC_ASSERT(BOOST_IDENTITY_TYPE(parenthesized_metafunction)::value)
+
+TMP_ASSERT_PAREN(( boost::is_const<std::map<int, char> const> ));
+TMP_ASSERT( BOOST_IDENTITY_TYPE((boost::is_const<std::map<int, char> const>)) );
+//]
+
+//[tmp_assert_alternative_always
+TMP_ASSERT_PAREN(( boost::is_const<int const> )); // Always extra `()`.
+TMP_ASSERT( boost::is_const<int const> ); // No extra `()` and no macro.
+//]
+
+int main() { return 0; }
+

Modified: sandbox/local_function/libs/utility/identity_type/test/var_err.cpp
==============================================================================
--- sandbox/local_function/libs/utility/identity_type/test/var_err.cpp (original)
+++ sandbox/local_function/libs/utility/identity_type/test/var_err.cpp 2012-01-25 16:43:43 EST (Wed, 25 Jan 2012)
@@ -1,11 +1,11 @@
 
 #include <map>
 
-//[test_var_err
-#define VAR(type, postfix) type var_ ## postfix
+//[var_err
+#define VAR(type, n) type var ## n
 
-VAR(int, a); // OK.
-VAR(std::map<char, int>, b); // Error.
+VAR( int, 1 ); // OK.
+VAR( std::map<int, char>, 2 ); // Error.
 //]
 
 int main() { return 0; }

Modified: sandbox/local_function/libs/utility/identity_type/test/var_ok.cpp
==============================================================================
--- sandbox/local_function/libs/utility/identity_type/test/var_ok.cpp (original)
+++ sandbox/local_function/libs/utility/identity_type/test/var_ok.cpp 2012-01-25 16:43:43 EST (Wed, 25 Jan 2012)
@@ -1,14 +1,19 @@
 
 #include <map>
 
-#define VAR(type, postfix) type var_ ## count
+#define VAR(type, n) type var ## n
 
-VAR(int, a); // OK.
+VAR( int, 1 ); // OK.
 
-//[test_var_ok
+//[var_typedef
+typedef std::map<int, char> map_type;
+VAR( map_type, 3 ); // OK.
+//]
+
+//[var_ok
 #include <boost/utility/identity_type.hpp>
 
-VAR(BOOST_IDENTITY_TYPE((std::map<char, int>)), b); // OK.
+VAR( BOOST_IDENTITY_TYPE((std::map<int, char>)), 4 ); // OK.
 //]
 
 int main() { return 0; }


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