Ticket #10347: 0001-Using-type_index-to-avoid-RTTIs-in-program_options.-.patch

File 0001-Using-type_index-to-avoid-RTTIs-in-program_options.-.patch, 2.5 KB (added by gongminmin@…, 8 years ago)

Using type_index to avoid RTTIs.

  • include/boost/program_options/value_semantic.hpp

    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  
    1212#include <boost/any.hpp>
    1313#include <boost/function/function1.hpp>
    1414#include <boost/lexical_cast.hpp>
     15#include <boost/type_index.hpp>
    1516
    1617
    1718#include <string>
    1819#include <vector>
    19 #include <typeinfo>
    2020#include <limits>
    2121
    2222namespace boost { namespace program_options {
    namespace boost { namespace program_options {  
    174174    public:
    175175        // Returns the type of the value described by this
    176176        // object.
    177         virtual const std::type_info& value_type() const = 0;
     177        virtual const boost::typeindex::type_info& value_type() const = 0;
    178178        // Not really needed, since deletion from this
    179179        // class is silly, but just in case.
    180180        virtual ~typed_value_base() {}
    namespace boost { namespace program_options {  
    359359
    360360    public: // typed_value_base overrides
    361361       
    362         const std::type_info& value_type() const
     362        const boost::typeindex::type_info& value_type() const
    363363        {
    364             return typeid(T);
     364            return boost::typeindex::type_id<T>().type_info();
    365365        }
    366366       
    367367
  • test/options_description_test.cpp

    diff --git a/test/options_description_test.cpp b/test/options_description_test.cpp
    index d443a7b..56233b6 100644
    a b void test_type()  
    2828    const typed_value_base* b = dynamic_cast<const typed_value_base*>
    2929        (desc.find("foo", false).semantic().get());
    3030    BOOST_CHECK(b);
    31     BOOST_CHECK(b->value_type() == typeid(int));
     31    BOOST_CHECK(b->value_type() == boost::typeindex::type_id<int>().type_info());
    3232
    3333    const typed_value_base* b2 = dynamic_cast<const typed_value_base*>
    3434        (desc.find("bar", false).semantic().get());
    3535    BOOST_CHECK(b2);
    36     BOOST_CHECK(b2->value_type() == typeid(string));
     36    BOOST_CHECK(b2->value_type() == boost::typeindex::type_id<string>().type_info());
    3737}
    3838
    3939void test_approximation()