|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r85538 - in trunk: boost/exception libs/exception/test
From: emil_at_[hidden]
Date: 2013-08-31 19:24:40
Author: emildotchevski
Date: 2013-08-31 19:24:40 EDT (Sat, 31 Aug 2013)
New Revision: 85538
URL: http://svn.boost.org/trac/boost/changeset/85538
Log:
N3757
Added:
trunk/boost/exception/N3757.hpp (contents, props changed)
trunk/libs/exception/test/N3757_test.cpp (contents, props changed)
Text files modified:
trunk/boost/exception/N3757.hpp | 46 +++++++++++++++++++++++++++
trunk/boost/exception/exception.hpp | 6 +++
trunk/libs/exception/test/Jamfile.v2 | 3 +
trunk/libs/exception/test/N3757_test.cpp | 67 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 121 insertions(+), 1 deletions(-)
Added: trunk/boost/exception/N3757.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/boost/exception/N3757.hpp 2013-08-31 19:24:40 EDT (Sat, 31 Aug 2013) (r85538)
@@ -0,0 +1,46 @@
+//Copyright (c) 2006-2013 Emil Dotchevski and Reverge Studios, Inc.
+
+//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)
+
+#ifndef UUID_9011016A11A711E3B46CD9FA6088709B
+#define UUID_9011016A11A711E3B46CD9FA6088709B
+#if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
+#pragma GCC system_header
+#endif
+#if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
+#pragma warning(push,1)
+#endif
+
+#include <boost/exception/info.hpp>
+#include <boost/exception/get_error_info.hpp>
+
+namespace
+boost
+ {
+ //Here we're using the boost::error_info machinery to store the info in the exception
+ //object. Within the context of N3757, this is strictly an implementation detail.
+
+ template <class Tag>
+ inline
+ void
+ exception::
+ set( typename Tag::type const & v )
+ {
+ exception_detail::set_info(*this,error_info<Tag,typename Tag::type>(v));
+ }
+
+ template <class Tag>
+ inline
+ typename Tag::type const *
+ exception::
+ get() const
+ {
+ return get_error_info<error_info<Tag,typename Tag::type> >(*this);
+ }
+ }
+
+#if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
+#pragma warning(pop)
+#endif
+#endif
Modified: trunk/boost/exception/exception.hpp
==============================================================================
--- trunk/boost/exception/exception.hpp Sat Aug 31 17:49:26 2013 (r85537)
+++ trunk/boost/exception/exception.hpp 2013-08-31 19:24:40 EDT (Sat, 31 Aug 2013) (r85538)
@@ -207,6 +207,12 @@
class
exception
{
+ //<N3757>
+ public:
+ template <class Tag> void set( typename Tag::type const & );
+ template <class Tag> typename Tag::type const * get() const;
+ //</N3757>
+
protected:
exception():
Modified: trunk/libs/exception/test/Jamfile.v2
==============================================================================
--- trunk/libs/exception/test/Jamfile.v2 Sat Aug 31 17:49:26 2013 (r85537)
+++ trunk/libs/exception/test/Jamfile.v2 2013-08-31 19:24:40 EDT (Sat, 31 Aug 2013) (r85538)
@@ -1,6 +1,6 @@
# Boost Exception Library test Jamfile
#
-# Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
+# Copyright (c) 2006-2013 Emil Dotchevski and Reverge Studios, Inc.
#
# 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)
@@ -42,6 +42,7 @@
run errinfos_test.cpp ;
run exception_ptr_test.cpp/<define>BOOST_ENABLE_NON_INTRUSIVE_EXCEPTION_PTR ../../thread/src/tss_null.cpp /boost/exception /boost//thread : : : <threading>multi : non_intrusive_exception_ptr_test ;
run exception_ptr_test.cpp ../../thread/src/tss_null.cpp /boost//thread : : : <threading>multi ;
+run N3757_test.cpp ;
compile-fail exception_fail.cpp ;
compile-fail throw_exception_fail.cpp ;
Added: trunk/libs/exception/test/N3757_test.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/exception/test/N3757_test.cpp 2013-08-31 19:24:40 EDT (Sat, 31 Aug 2013) (r85538)
@@ -0,0 +1,67 @@
+//Copyright (c) 2006-2013 Emil Dotchevski and Reverge Studios, Inc.
+
+//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)
+
+//This file tests the N3757 syntax for adding error info to std::exception, which is
+//different from the syntax used by Boost Exception.
+
+#include <boost/exception/N3757.hpp>
+#include <boost/exception/diagnostic_information.hpp>
+#include <boost/detail/lightweight_test.hpp>
+#include <ostream>
+
+struct tag1 { typedef int type; };
+struct tag2 { typedef std::string type; };
+struct tag3 { typedef int type; };
+
+struct my_error_code { int ec; my_error_code(int ec):ec(ec){ } };
+struct tag_error_code { typedef my_error_code type; };
+
+bool my_error_code_to_string_called=false;
+
+std::ostream &
+operator<<( std::ostream & s, my_error_code const & x )
+{
+ my_error_code_to_string_called=true;
+ return s << "my_error_code(" << x.ec << ')';
+}
+
+struct my_exception: virtual std::exception, virtual boost::exception { };
+
+int
+main()
+ {
+ try
+ {
+ throw my_exception();
+ }
+ catch(
+ boost::exception & e )
+ {
+ e.set<tag1>(42);
+ e.set<tag2>("42");
+ e.set<tag_error_code>(42); //Implicit conversion
+ try
+ {
+ throw;
+ }
+ catch(
+ my_exception & e )
+ {
+ BOOST_TEST(e.get<tag1>() && *e.get<tag1>()==42);
+ BOOST_TEST(e.get<tag2>() && *e.get<tag2>()=="42");
+ BOOST_TEST(!e.get<tag3>());
+ BOOST_TEST(e.get<tag_error_code>() && e.get<tag_error_code>()->ec==42);
+
+ //Below we're verifying that an error code wrapped in a user-defined type
+ //invokes the correct op<< to convert the error code to string.
+ //Note that N3757 diagnostic_information uses different syntax, it is a
+ //member of of std::exception.
+ std::string di=boost::diagnostic_information(e);
+ BOOST_TEST(!di.empty());
+ BOOST_TEST(my_error_code_to_string_called);
+ }
+ }
+ return boost::report_errors();
+ }
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