From 5bc362e4f303f18b9e70b60ee975ad1491bbdc5e Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Wed, 21 Jan 2009 18:01:14 +0000 Subject: [PATCH] System: provide optional throws function rather than throws object [SVN r50705] --- include/boost/system/error_code.hpp | 10 ++++++++++ src/error_code.cpp | 2 ++ 2 files changed, 12 insertions(+) diff --git a/include/boost/system/error_code.hpp b/include/boost/system/error_code.hpp index 8f795d7..55c3b04 100644 --- a/include/boost/system/error_code.hpp +++ b/include/boost/system/error_code.hpp @@ -384,7 +384,17 @@ namespace boost }; // predefined error_code object used as "throw on error" tag +# ifndef BOOST_SYSTEM_THROWS_FUNCTION BOOST_SYSTEM_DECL extern error_code throws; +# else + namespace detail { inline error_code * throws() { return 0; } } + // prevent misuse by poisoning the reference in a way that doesn't + // produce warnings or errors from popular compilers, and is also + // very efficient (as determined by inspectiing generated code) + + inline error_code & throws() + { return *detail::throws(); } +# endif // non-member functions ------------------------------------------------// diff --git a/src/error_code.cpp b/src/error_code.cpp index 030ab70..fac174e 100644 --- a/src/error_code.cpp +++ b/src/error_code.cpp @@ -411,11 +411,13 @@ namespace boost namespace system { +# ifndef BOOST_SYSTEM_THROWS_FUNCTION BOOST_SYSTEM_DECL error_code throws; // "throw on error" special error_code; // note that it doesn't matter if this // isn't initialized before use since // the only use is to take its // address for comparison purposes +# endif BOOST_SYSTEM_DECL const error_category & get_system_category() {