? libs/any/a.out Index: boost/any.hpp =================================================================== RCS file: /cvsroot/boost/boost/boost/any.hpp,v retrieving revision 1.9 diff -u -r1.9 any.hpp --- boost/any.hpp 16 Sep 2004 11:23:30 -0000 1.9 +++ boost/any.hpp 16 Feb 2005 08:41:00 -0000 @@ -14,6 +14,7 @@ #include #include "boost/config.hpp" +#include #include namespace boost @@ -170,12 +171,24 @@ template ValueType any_cast(const any & operand) { - const ValueType * result = any_cast(&operand); + typedef typename remove_reference::type value_type; + const value_type * result = any_cast(&operand); if(!result) boost::throw_exception(bad_any_cast()); return *result; } + template + ValueType any_cast(any & operand) + { + typedef typename remove_reference::type value_type; + value_type * result = any_cast(&operand); + if(!result) + boost::throw_exception(bad_any_cast()); + return *result; + } + + } // Copyright Kevlin Henney, 2000, 2001, 2002. All rights reserved. Index: libs/any/any_test.cpp =================================================================== RCS file: /cvsroot/boost/boost/libs/any/any_test.cpp,v retrieving revision 1.4 diff -u -r1.4 any_test.cpp --- libs/any/any_test.cpp 11 Oct 2004 10:45:27 -0000 1.4 +++ libs/any/any_test.cpp 16 Feb 2005 08:41:00 -0000 @@ -35,6 +35,7 @@ void test_bad_cast(); void test_swap(); void test_null_copying(); + void test_cast_to_reference(); const test_case test_cases[] = { @@ -45,7 +46,8 @@ { "converting assignment operator", test_converting_assign }, { "failed custom keyword cast", test_bad_cast }, { "swap member function", test_swap }, - { "copying operations on a null", test_null_copying } + { "copying operations on a null", test_null_copying }, + { "casting to reference", test_cast_to_reference } }; const test_case_iterator begin = test_cases; @@ -185,6 +187,15 @@ check_true(copied.empty(), "empty on copied"); check_true(assigned.empty(), "empty on copied"); } + + void test_cast_to_reference() + { + int i = 1; + any a = i; + int& i2 = any_cast(a); + i2 = 2; + check_equal(any_cast(a), 2, "value was modified"); + } } // Copyright Kevlin Henney, 2000, 2001. All rights reserved. @@ -192,4 +203,4 @@ // Distributed under 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) -// \ No newline at end of file +//