c++ - templated function which accepts only string or arithmetic -


i'm trying work:

template<class type> typename boost::enable_if< boost::mpl::or_< boost::is_arithmetic<type>, is_string<type> > >::type get(const std::string &argpath, const type &argdefault) {     bool caught = false;     std::stringstream ss;     type value;      try {         value = ptree_.get<type>(argpath);     } catch(ptree_bad_path &e) {         caught = true;     }      if(caught)         value = argdefault;      ss << value;     parameters_.insert(std::pair<std::string, std::string>(argpath, ss.str()));     return value; } 

i used following is_string type trait: type trait strings

my goal restrict type string or arithmetic type can push stringstream.

so builds, when try use it, returns following errors:

error: void value not ignored ought

in member function ‘typename boost::enable_if, is_string, mpl_::bool_, mpl_::bool_, mpl_::bool_ >, void>::type fooclass::get(const std::string&, const type&) [with type = uint8_t]’

error: return-statement value, in function returning 'void'

here how try use it:

fooclass f; item_value = f.get("tag1.tag2.item", default_item_value); 

any appreciated, in advance!

from http://www.boost.org/doc/libs/1_53_0/libs/utility/enable_if.html, enable_if has second parameter defaults void:

template <bool b, class t = void> struct enable_if_c {   typedef t type; }; 

seems me need include return type in enable_if. (it defaulting void now.)

template<class type> typename boost::enable_if< boost::mpl::or_<     boost::is_arithmetic<type>,     is_string<type> >, type >::type get(const std::string &argpath, const type &argdefault); 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -