Boost logo

Boost-Commit :

From: garcia_at_[hidden]
Date: 2008-07-10 15:29:02


Author: garcia
Date: 2008-07-10 15:29:02 EDT (Thu, 10 Jul 2008)
New Revision: 47296
URL: http://svn.boost.org/trac/boost/changeset/47296

Log:
Added tests for unwrap_ref.

Text files modified:
   trunk/libs/utility/ref_test.cpp | 42 ++++++++++++++++++++++++++++++++++++++++
   1 files changed, 42 insertions(+), 0 deletions(-)

Modified: trunk/libs/utility/ref_test.cpp
==============================================================================
--- trunk/libs/utility/ref_test.cpp (original)
+++ trunk/libs/utility/ref_test.cpp 2008-07-10 15:29:02 EDT (Thu, 10 Jul 2008)
@@ -68,11 +68,53 @@
     }
 };
 
+struct copy_counter {
+ static int count_;
+ copy_counter(copy_counter const& other) {
+ ++count_;
+ }
+ copy_counter() {}
+ static void reset() { count_ = 0; }
+ static int count() { return copy_counter::count_; }
+};
+
+int copy_counter::count_ = 0;
+
 } // namespace unnamed
 
+template <class T>
+void do_unwrap(T t) {
+
+ /* typename unwrap_reference<T>::type& lt = */
+ unwrap_ref(t);
+
+}
+
+void unwrap_test() {
+
+ int i = 3;
+ const int ci = 2;
+
+ do_unwrap(i);
+ do_unwrap(ci);
+ do_unwrap(ref(i));
+ do_unwrap(cref(ci));
+ do_unwrap(ref(ci));
+
+ copy_counter cc;
+ BOOST_CHECK(cc.count() == 0);
+
+ do_unwrap(cc);
+ do_unwrap(ref(cc));
+ do_unwrap(cref(cc));
+
+ BOOST_CHECK(cc.count() == 1);
+}
+
 int test_main(int, char * [])
 {
     ref_wrapper<int>::test(1);
     ref_wrapper<int const>::test(1);
+ unwrap_test();
     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