|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r84140 - in trunk: boost libs/any libs/any/test
From: antoshkka_at_[hidden]
Date: 2013-05-04 15:01:28
Author: apolukhin
Date: 2013-05-04 15:01:27 EDT (Sat, 04 May 2013)
New Revision: 84140
URL: http://svn.boost.org/trac/boost/changeset/84140
Log:
Make Boost.Any more conformant to draft:
* decay ValueType (partially refs #6999)
* experimental any_cast<rvalue&&>
Text files modified:
trunk/boost/any.hpp | 9 +++++----
trunk/libs/any/any_test.cpp | 23 ++++++++++++++++++++++-
trunk/libs/any/test/any_test_rv.cpp | 39 ++++++++++++++++++++++++++++++++++++++-
3 files changed, 65 insertions(+), 6 deletions(-)
Modified: trunk/boost/any.hpp
==============================================================================
--- trunk/boost/any.hpp (original)
+++ trunk/boost/any.hpp 2013-05-04 15:01:27 EDT (Sat, 04 May 2013)
@@ -19,6 +19,7 @@
#include "boost/config.hpp"
#include <boost/type_traits/remove_reference.hpp>
+#include <boost/type_traits/decay.hpp>
#include <boost/type_traits/is_reference.hpp>
#include <boost/throw_exception.hpp>
#include <boost/static_assert.hpp>
@@ -49,7 +50,7 @@
template<typename ValueType>
any(const ValueType & value)
- : content(new holder<ValueType>(value))
+ : content(new holder<BOOST_DEDUCED_TYPENAME decay<const ValueType>::type>(value))
{
}
@@ -69,7 +70,7 @@
// Perfect forwarding of ValueType
template<typename ValueType>
any(ValueType&& value, typename boost::disable_if<boost::is_same<any&, ValueType> >::type* = 0)
- : content(new holder< typename remove_reference<ValueType>::type >(static_cast<ValueType&&>(value)))
+ : content(new holder< typename decay<ValueType>::type >(static_cast<ValueType&&>(value)))
{
}
#endif
@@ -224,7 +225,7 @@
class bad_any_cast : public std::bad_cast
{
public:
- virtual const char * what() const throw()
+ virtual const char * what() const BOOST_NOEXCEPT_OR_NOTHROW
{
return "boost::bad_any_cast: "
"failed conversion using boost::any_cast";
@@ -268,7 +269,7 @@
nonref * result = any_cast<nonref>(&operand);
if(!result)
boost::throw_exception(bad_any_cast());
- return *result;
+ return static_cast<ValueType>(*result);
}
template<typename ValueType>
Modified: trunk/libs/any/any_test.cpp
==============================================================================
--- trunk/libs/any/any_test.cpp (original)
+++ trunk/libs/any/any_test.cpp 2013-05-04 15:01:27 EDT (Sat, 04 May 2013)
@@ -36,6 +36,7 @@
void test_swap();
void test_null_copying();
void test_cast_to_reference();
+ void test_with_array();
const test_case test_cases[] =
{
@@ -47,7 +48,8 @@
{ "failed custom keyword cast", test_bad_cast },
{ "swap member function", test_swap },
{ "copying operations on a null", test_null_copying },
- { "cast to reference types", test_cast_to_reference }
+ { "cast to reference types", test_cast_to_reference },
+ { "storing an array inside", test_with_array }
};
const test_case_iterator begin = test_cases;
@@ -249,6 +251,25 @@
"any_cast to incorrect const reference type");
}
+ void test_with_array()
+ {
+ any value1("Char array");
+ any value2;
+ value2 = "Char array";
+
+ check_false(value1.empty(), "type");
+ check_false(value2.empty(), "type");
+
+ check_equal(value1.type(), typeid(const char*), "type");
+ check_equal(value2.type(), typeid(const char*), "type");
+
+ check_non_null(any_cast<const char*>(&value1), "any_cast<const char*>");
+ check_non_null(any_cast<const char*>(&value2), "any_cast<const char*>");
+
+ check_null(any_cast<const char[1]>(&value1), "any_cast<const char[1]>");
+ check_null(any_cast<const char[1]>(&value2), "any_cast<const char[1]>");
+ }
+
}
// Copyright Kevlin Henney, 2000, 2001. All rights reserved.
Modified: trunk/libs/any/test/any_test_rv.cpp
==============================================================================
--- trunk/libs/any/test/any_test_rv.cpp (original)
+++ trunk/libs/any/test/any_test_rv.cpp 2013-05-04 15:01:27 EDT (Sat, 04 May 2013)
@@ -51,6 +51,7 @@
void test_move_assignment_from_value();
void test_copy_construction_from_value();
void test_copy_assignment_from_value();
+ void test_cast_to_rv();
const test_case test_cases[] =
@@ -63,7 +64,8 @@
{ "move construction from value", test_move_construction_from_value },
{ "move assignment from value", test_move_assignment_from_value },
{ "copy construction from value", test_copy_construction_from_value },
- { "copy assignment from value", test_copy_assignment_from_value }
+ { "copy assignment from value", test_copy_assignment_from_value },
+ { "casting to rvalue reference", test_cast_to_rv }
};
const test_case_iterator begin = test_cases;
@@ -272,6 +274,41 @@
move_copy_conting_class::moves_count, 0u,
"checking move counts");
}
+
+ void test_cast_to_rv()
+ {
+ move_copy_conting_class value0;
+ any value;
+ value = value0;
+ move_copy_conting_class::copy_count = 0;
+ move_copy_conting_class::moves_count = 0;
+
+ move_copy_conting_class value1 = any_cast<move_copy_conting_class&&>(value);
+
+ check_equal(
+ move_copy_conting_class::copy_count, 0u,
+ "checking copy counts");
+ check_equal(
+ move_copy_conting_class::moves_count, 1u,
+ "checking move counts");
+ (void)value1;
+/* Following code shall fail to compile
+ const any cvalue = value0;
+ move_copy_conting_class::copy_count = 0;
+ move_copy_conting_class::moves_count = 0;
+
+ move_copy_conting_class value2 = any_cast<move_copy_conting_class&&>(cvalue);
+
+ check_equal(
+ move_copy_conting_class::copy_count, 1u,
+ "checking copy counts");
+ check_equal(
+ move_copy_conting_class::moves_count, 0u,
+ "checking move counts");
+ (void)value2;
+*/
+ }
+
}
#endif
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