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

This is an old version of boost. Click here for the latest version's documentation home page.

Class option_description

boost::program_options::option_description —


class option_description {
// construct/copy/destruct
option_description(const char *, const value_semantic *);
option_description(const char *, const value_semantic *, const char *);

// public member functions
const std::string & short_name() const;
const std::string & long_name() const;
const std::string & description() const;
shared_ptr< const value_semantic > semantic() const;
std::string format_name() const;
std::string format_parameter() const;

// private member functions
option_description & name(const char *) ;


Describes one possible command line/config file option. There are two kinds of properties of an option. First describe it syntactically and are used only to validate input. Second affect interpretation of the option, for example default value for it or function that should be called when the value is finally known. Routines which perform parsing never use second kind of properties -- they are side effect free.


option_description construct/copy/destruct

  1. option_description();
  2. option_description(const char * name, const value_semantic * s);

    Initializes the object with the passed data.

    Note: it would be nice to make the second parameter auto_ptr, to explicitly pass ownership. Unfortunately, it's often needed to create objects of types derived from 'value_semantic': options_description d; d.add_options()("a", parameter<int>("n")->default_value(1)); Here, the static type returned by 'parameter' should be derived from value_semantic.

    Alas, derived->base conversion for auto_ptr does not really work, see

    So, we have to use plain old pointers. Besides, users are not expected to use the constructor directly.

    The 'name' parameter is interpreted by the following rules:

    • if there's no "," character in 'name', it specifies long name

    • otherwise, the part before "," specifies long name and the part after -- long name.

  3. option_description(const char * name, const value_semantic * s, 
    const char * description);

    Initializes the class with the passed data.

  4. ~option_description();

option_description public member functions

  1. const std::string & short_name() const;
  2. const std::string & long_name() const;
  3. const std::string & description() const;
  4. shared_ptr< const value_semantic > semantic() const;
  5. std::string format_name() const;
  6. std::string format_parameter() const;

    Return the parameter name and properties, formatted suitably for usage message.

option_description private member functions

  1. option_description & name(const char * name) ;
Copyright 2002-2004 Vladimir Prus