From 6feeeb3b92c551434b571bbb7d6faebbee562278 Mon Sep 17 00:00:00 2001 From: Minmin Gong Date: Mon, 27 Apr 2015 22:52:38 -0700 Subject: [PATCH] Using type_index to avoid RTTIs in program_options. (fixes #10347) --- .../boost/program_options/value_semantic.hpp | 18 ++++++++++++------ test/Jamfile.v2 | 1 + test/options_description_test.cpp | 6 ++++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/include/boost/program_options/value_semantic.hpp b/include/boost/program_options/value_semantic.hpp index 16e8d65..00ea8cb 100644 --- a/include/boost/program_options/value_semantic.hpp +++ b/include/boost/program_options/value_semantic.hpp @@ -12,11 +12,11 @@ #include #include #include +#include #include #include -#include #include namespace boost { namespace program_options { @@ -163,6 +163,7 @@ namespace boost { namespace program_options { bool m_zero_tokens; }; +#ifndef BOOST_NO_RTTI /** Base class for all option that have a fixed type, and are willing to announce this type to the outside world. Any 'value_semantics' for which you want to find out the @@ -174,17 +175,20 @@ namespace boost { namespace program_options { public: // Returns the type of the value described by this // object. - virtual const std::type_info& value_type() const = 0; + virtual const boost::typeindex::type_info& value_type() const = 0; // Not really needed, since deletion from this // class is silly, but just in case. virtual ~typed_value_base() {} }; +#endif /** Class which handles value of a specific type. */ template - class typed_value : public value_semantic_codecvt_helper, - public typed_value_base + class typed_value : public value_semantic_codecvt_helper +#ifndef BOOST_NO_RTTI + , public typed_value_base +#endif { public: /** Ctor. The 'store_to' parameter tells where to store @@ -359,10 +363,12 @@ namespace boost { namespace program_options { public: // typed_value_base overrides - const std::type_info& value_type() const +#ifndef BOOST_NO_RTTI + const boost::typeindex::type_info& value_type() const { - return typeid(T); + return boost::typeindex::type_id().type_info(); } +#endif private: diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index e18e008..41b41cf 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -33,6 +33,7 @@ test-suite program_options : [ po-test unrecognized_test.cpp ] [ po-test required_test.cpp : required_test.cfg ] [ po-test exception_txt_test.cpp ] + [ run options_description_test.cpp : : : off BOOST_NO_RTTI BOOST_NO_TYPEID : options_description_no_rtti_test ] ; exe test_convert : test_convert.cpp ; diff --git a/test/options_description_test.cpp b/test/options_description_test.cpp index d443a7b..695f1d9 100644 --- a/test/options_description_test.cpp +++ b/test/options_description_test.cpp @@ -25,15 +25,17 @@ void test_type() ("bar", value(), "") ; +#ifndef BOOST_NO_RTTI const typed_value_base* b = dynamic_cast (desc.find("foo", false).semantic().get()); BOOST_CHECK(b); - BOOST_CHECK(b->value_type() == typeid(int)); + BOOST_CHECK(b->value_type() == boost::typeindex::type_id()); const typed_value_base* b2 = dynamic_cast (desc.find("bar", false).semantic().get()); BOOST_CHECK(b2); - BOOST_CHECK(b2->value_type() == typeid(string)); + BOOST_CHECK(b2->value_type() == boost::typeindex::type_id()); +#endif } void test_approximation()