Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

Class variable_value

boost::program_options::variable_value

Synopsis

// In header: <boost/program_options/variables_map.hpp>


class variable_value {
public:

  // friend functions
  BOOST_PROGRAM_OPTIONS_DECL void 
  store(const basic_parsed_options< char > &, variables_map &, bool);

  // public member functions
  variable_value();
  variable_value(const boost::any &, bool);
  template<typename T> const T & as() const;
  template<typename T> T & as();
  bool empty() const;
  bool defaulted() const;
  const boost::any & value() const;
  boost::any & value();
};

Description

Class holding value of option. Contains details about how the value is set and allows to conveniently obtain the value.

variable_value friend functions

  1. BOOST_PROGRAM_OPTIONS_DECL void 
    store(const basic_parsed_options< char > & options, variables_map & m, bool);

    Stores in 'm' all options that are defined in 'options'. If 'm' already has a non-defaulted value of an option, that value is not changed, even if 'options' specify some value.

variable_value public member functions

  1. variable_value();
  2. variable_value(const boost::any & xv, bool xdefaulted);
  3. template<typename T> const T & as() const;

    If stored value if of type T, returns that value. Otherwise, throws boost::bad_any_cast exception.

  4. template<typename T> T & as();

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  5. bool empty() const;
    Returns true if no value is stored.
  6. bool defaulted() const;

    Returns true if the value was not explicitly given, but has default value.

  7. const boost::any & value() const;

    Returns the contained value.

  8. boost::any & value();

    Returns the contained value.


PrevUpHomeNext