$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r64872 - in sandbox/chrono/libs/chrono: build example test
From: vicente.botet_at_[hidden]
Date: 2010-08-17 16:28:42
Author: viboes
Date: 2010-08-17 16:28:39 EDT (Tue, 17 Aug 2010)
New Revision: 64872
URL: http://svn.boost.org/trac/boost/changeset/64872
Log:
Added some tests
Added:
   sandbox/chrono/libs/chrono/test/common_type_fails.cpp   (contents, props changed)
Text files modified: 
   sandbox/chrono/libs/chrono/build/Jamfile.v2                          |     2 ++                                      
   sandbox/chrono/libs/chrono/example/function_stopclock_example.cpp    |     6 +++---                                  
   sandbox/chrono/libs/chrono/example/scoped_stopclock_example.cpp      |     6 +++---                                  
   sandbox/chrono/libs/chrono/example/stopclock_accumulator_example.cpp |    15 ++++++++-------                         
   sandbox/chrono/libs/chrono/example/stopclock_example.cpp             |     6 +++---                                  
   sandbox/chrono/libs/chrono/test/Jamfile.v2                           |     7 ++++---                                 
   sandbox/chrono/libs/chrono/test/common_type_test.cpp                 |    29 +++++++++++++++++++++++------           
   7 files changed, 46 insertions(+), 25 deletions(-)
Modified: sandbox/chrono/libs/chrono/build/Jamfile.v2
==============================================================================
--- sandbox/chrono/libs/chrono/build/Jamfile.v2	(original)
+++ sandbox/chrono/libs/chrono/build/Jamfile.v2	2010-08-17 16:28:39 EDT (Tue, 17 Aug 2010)
@@ -31,6 +31,7 @@
         #<define>BOOST_CHRONO_USES_MPL_ASSERT
         #<define>BOOST_RATIO_USES_ARRAY_ASSERT
         #<define>BOOST_CHRONO_USES_ARRAY_ASSERT
+        <define>BOOST_COMMON_TYPE_DONT_USE_TYPEOF
         #<toolset>gcc:<linkflags>--enable-auto-import        
     : usage-requirements  # pass these requirement to dependents (i.e. users)
         #<os>LINUX:<threading>multi
@@ -44,6 +45,7 @@
         #<define>BOOST_COMMON_TYPE_USES_ARRAY_ASSERT
         #<define>BOOST_RATIO_USES_ARRAY_ASSERT
         #<define>BOOST_CHRONO_USES_ARRAY_ASSERT
+        <define>BOOST_COMMON_TYPE_DONT_USE_TYPEOF
         <link>shared:<define>BOOST_CHRONO_DYN_LINK=1
         <link>static:<define>BOOST_CHRONO_STATIC_LINK=1
     ;
Modified: sandbox/chrono/libs/chrono/example/function_stopclock_example.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/example/function_stopclock_example.cpp	(original)
+++ sandbox/chrono/libs/chrono/example/function_stopclock_example.cpp	2010-08-17 16:28:39 EDT (Tue, 17 Aug 2010)
@@ -24,8 +24,8 @@
 {
   function_stopclock<> _(BOOST_CURRENT_FUNCTION);   
 
-  f1(100000);
-  f1(200000);
-  f1(300000);
+  f1(1000);
+  f1(2000);
+  f1(3000);
   return 0;
 }
Modified: sandbox/chrono/libs/chrono/example/scoped_stopclock_example.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/example/scoped_stopclock_example.cpp	(original)
+++ sandbox/chrono/libs/chrono/example/scoped_stopclock_example.cpp	2010-08-17 16:28:39 EDT (Tue, 17 Aug 2010)
@@ -24,8 +24,8 @@
 {
   scoped_stopclock<> _(BOOST_CURRENT_FUNCTION);   
 
-  f1(100000);
-  f1(200000);
-  f1(300000);
+  f1(1000);
+  f1(2000);
+  f1(3000);
   return 0;
 }
Modified: sandbox/chrono/libs/chrono/example/stopclock_accumulator_example.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/example/stopclock_accumulator_example.cpp	(original)
+++ sandbox/chrono/libs/chrono/example/stopclock_accumulator_example.cpp	2010-08-17 16:28:39 EDT (Tue, 17 Aug 2010)
@@ -15,10 +15,11 @@
 #include "sleep_for.hpp"
 
 using namespace boost::chrono;
+template <typename Clock>
 int f1(long j)
 {
-  static stopclock_accumulator<> acc(BOOST_CHRONO_ACCUMULATOR_FUNCTION_FORMAT);
-  stopclock_accumulator<>::scoped_run _(acc);
+  static stopclock_accumulator<Clock> acc(BOOST_CHRONO_ACCUMULATOR_FUNCTION_FORMAT);
+  typename stopclock_accumulator<Clock>::scoped_run _(acc);
 
   for ( long i = 0; i < j; ++i )
     std::sqrt( 123.456L );  // burn some time
@@ -29,11 +30,11 @@
 }
 int main()
 {
-  static stopclock_accumulator<> acc(BOOST_CHRONO_ACCUMULATOR_FUNCTION_FORMAT);
-  stopclock_accumulator<>::scoped_run _(acc);
+  static stopclock_accumulator<process_cpu_clock> acc(BOOST_CHRONO_ACCUMULATOR_FUNCTION_FORMAT);
+  stopclock_accumulator<process_cpu_clock>::scoped_run _(acc);
 
-  f1(100000);
-  f1(200000);
-  f1(300000);
+  f1<high_resolution_clock>(1000);
+  f1<high_resolution_clock>(2000);
+  f1<high_resolution_clock>(3000);
   return 0;
 }
Modified: sandbox/chrono/libs/chrono/example/stopclock_example.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/example/stopclock_example.cpp	(original)
+++ sandbox/chrono/libs/chrono/example/stopclock_example.cpp	2010-08-17 16:28:39 EDT (Tue, 17 Aug 2010)
@@ -24,8 +24,8 @@
 {
   stopclock<> _(BOOST_CHRONO_TIME_FUNCTION_FORMAT);   
 
-  f1(100000);
-  f1(200000);
-  f1(300000);
+  f1(1000);
+  f1(2000);
+  f1(3000);
   return 0;
 }
Modified: sandbox/chrono/libs/chrono/test/Jamfile.v2
==============================================================================
--- sandbox/chrono/libs/chrono/test/Jamfile.v2	(original)
+++ sandbox/chrono/libs/chrono/test/Jamfile.v2	2010-08-17 16:28:39 EDT (Tue, 17 Aug 2010)
@@ -31,9 +31,10 @@
     ;
 
    test-suite "common_type"
-       :
-         [ run common_type_test.cpp ]
-         ;
+        :
+        [ run common_type_test.cpp ]
+        [ compile-fail common_type_fails.cpp  ]
+        ;
 
     test-suite "ratio"
         :
Added: sandbox/chrono/libs/chrono/test/common_type_fails.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/test/common_type_fails.cpp	2010-08-17 16:28:39 EDT (Tue, 17 Aug 2010)
@@ -0,0 +1,41 @@
+//  common_type_test.cpp  ----------------------------------------------------//
+
+//  Copyright 2010 Beman Dawes
+
+//  Distributed under the Boost Software License, Version 1.0.
+//  See http://www.boost.org/LICENSE_1_0.txt
+
+#define _CRT_SECURE_NO_WARNINGS  // disable VC++ foolishness
+
+#define STD2
+#ifndef STD 
+#include <boost/type_traits/common_type.hpp>
+#else
+#include <type_traits>
+#endif
+#include <iostream>
+
+
+#include <boost/test/minimal.hpp>
+
+struct C1 {
+    //~ private:
+        //~ C1();
+};
+    
+struct C2 {};
+
+
+
+#ifndef STD 
+typedef boost::common_type<C1, C2>::type AC;
+#else
+typedef std::common_type<C1, C2>::type AC;
+#endif    
+//~ AC* ac;
+   
+
+int test_main( int argc, char * argv[] ) 
+{    
+    return 0;
+}
\ No newline at end of file
Modified: sandbox/chrono/libs/chrono/test/common_type_test.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/test/common_type_test.cpp	(original)
+++ sandbox/chrono/libs/chrono/test/common_type_test.cpp	2010-08-17 16:28:39 EDT (Tue, 17 Aug 2010)
@@ -16,6 +16,8 @@
     
 struct C2 {};
 
+    
+struct C3 : C2 {};
 struct C1C2 {
     C1C2() {}
     C1C2(C1 const&) {}
@@ -47,11 +49,7 @@
 
 template <typename C, typename A, typename B>
 void assignation_3() {
-#if 0
-typedef typename boost::common_type<A, B, C>::type ABC; // DO not compile
-#else
 typedef typename boost::common_type<C, A, B>::type ABC;
-#endif
     A a;
     B b;
     C c;
@@ -66,10 +64,29 @@
     f3<C, A, B>(c);
 }
 
+C1C2 c1c2;
+C1 c1;
+
+int f(C1C2 ) { return 1;}
+int f(C1 ) { return 2;}
+template <typename OSTREAM>
+OSTREAM& operator<<(OSTREAM& os, C1 const&) {return os;}
+
+C1C2& declval_C1C2() {return c1c2;}
+C1& declval_C1(){return c1;}
+bool declval_bool(){return true;}
+
 int test_main( int argc, char * argv[] )
 {
-    //~ assignation_2<C1, C2>(); // fails
     assignation_2<C1C2, C1>();
+    //~ typedef boost::common_type<C1C2&, C1&>::type T1; // fails if BOOST_COMMON_TYPE_DONT_USE_TYPEOF
+    std::cout << f(declval_bool()?declval_C1C2():declval_C1()) << std::endl;
+    typedef boost::common_type<C3*, C2*>::type T2;
+    typedef boost::common_type<int*, int const*>::type T3;
+    //~ typedef boost::common_type<int volatile*, int const*>::type T4; // fails if BOOST_COMMON_TYPE_DONT_USE_TYPEOF
+    typedef boost::common_type<int*, int volatile*>::type T5;
+    //~ typedef boost::common_type<short volatile*, int const*>::type T5; // fails
+
     assignation_2<C1, C1C2>();
     assignation_2<C1C2, C2>();
     assignation_2<C2, C1C2>();
@@ -77,6 +94,6 @@
     assignation_3<C1C2, C1, C2>();
     assignation_3<C2, C1C2, C1>();
     assignation_3<C1C2, C2, C1>();
-    //~ assignation_3<C1, C2, C1C2>(); // fails
+    //~ assignation_3<C1, C2, C1C2>(); // fails because the common type is the third
     return 0;
 }