From 28adee95188e7bdf2c876c09c5084f9e325f3a21 Mon Sep 17 00:00:00 2001
From: Minmin Gong <minmin.gong@gmail.com>
Date: Tue, 3 Mar 2015 00:01:47 -0800
Subject: [PATCH] Using type_index to avoid RTTIs in program_options. (fixes
#10347)
---
include/boost/program_options/value_semantic.hpp | 8 ++++----
test/options_description_test.cpp | 4 ++--
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/include/boost/program_options/value_semantic.hpp b/include/boost/program_options/value_semantic.hpp
index bb377a2..6b01cf2 100644
a
|
b
|
|
12 | 12 | #include <boost/any.hpp> |
13 | 13 | #include <boost/function/function1.hpp> |
14 | 14 | #include <boost/lexical_cast.hpp> |
| 15 | #include <boost/type_index.hpp> |
15 | 16 | |
16 | 17 | |
17 | 18 | #include <string> |
18 | 19 | #include <vector> |
19 | | #include <typeinfo> |
20 | 20 | #include <limits> |
21 | 21 | |
22 | 22 | namespace boost { namespace program_options { |
… |
… |
namespace boost { namespace program_options {
|
174 | 174 | public: |
175 | 175 | // Returns the type of the value described by this |
176 | 176 | // object. |
177 | | virtual const std::type_info& value_type() const = 0; |
| 177 | virtual const boost::typeindex::type_info& value_type() const = 0; |
178 | 178 | // Not really needed, since deletion from this |
179 | 179 | // class is silly, but just in case. |
180 | 180 | virtual ~typed_value_base() {} |
… |
… |
namespace boost { namespace program_options {
|
359 | 359 | |
360 | 360 | public: // typed_value_base overrides |
361 | 361 | |
362 | | const std::type_info& value_type() const |
| 362 | const boost::typeindex::type_info& value_type() const |
363 | 363 | { |
364 | | return typeid(T); |
| 364 | return boost::typeindex::type_id<T>().type_info(); |
365 | 365 | } |
366 | 366 | |
367 | 367 | |
diff --git a/test/options_description_test.cpp b/test/options_description_test.cpp
index d443a7b..56233b6 100644
a
|
b
|
void test_type()
|
28 | 28 | const typed_value_base* b = dynamic_cast<const typed_value_base*> |
29 | 29 | (desc.find("foo", false).semantic().get()); |
30 | 30 | BOOST_CHECK(b); |
31 | | BOOST_CHECK(b->value_type() == typeid(int)); |
| 31 | BOOST_CHECK(b->value_type() == boost::typeindex::type_id<int>().type_info()); |
32 | 32 | |
33 | 33 | const typed_value_base* b2 = dynamic_cast<const typed_value_base*> |
34 | 34 | (desc.find("bar", false).semantic().get()); |
35 | 35 | BOOST_CHECK(b2); |
36 | | BOOST_CHECK(b2->value_type() == typeid(string)); |
| 36 | BOOST_CHECK(b2->value_type() == boost::typeindex::type_id<string>().type_info()); |
37 | 37 | } |
38 | 38 | |
39 | 39 | void test_approximation() |