Skip to content

Don't require non-const reference to call notify() #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/boost/program_options/variables_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace boost { namespace program_options {


/** Runs all 'notify' function for options in 'm'. */
BOOST_PROGRAM_OPTIONS_DECL void notify(variables_map& m);
BOOST_PROGRAM_OPTIONS_DECL void notify(const variables_map& m);

/** Class holding value of option. Contains details about how the
value is set and allows to conveniently obtain the value.
Expand Down Expand Up @@ -157,7 +157,7 @@ namespace boost { namespace program_options {
// Override to clear some extra fields.
void clear();

void notify();
void notify() const;

private:
/** Implementation of abstract_variables_map::get
Expand Down
7 changes: 3 additions & 4 deletions src/variables_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace boost { namespace program_options {
}

BOOST_PROGRAM_OPTIONS_DECL
void notify(variables_map& vm)
void notify(const variables_map& vm)
{
vm.notify();
}
Expand Down Expand Up @@ -210,7 +210,7 @@ namespace boost { namespace program_options {
}

void
variables_map::notify()
variables_map::notify() const
{
// This checks if all required options occur
for (map<string, string>::const_iterator r = m_required.begin();
Expand All @@ -223,12 +223,11 @@ namespace boost { namespace program_options {
if (iter == end() || iter->second.empty())
{
boost::throw_exception(required_option(display_opt));

}
}

// Lastly, run notify actions.
for (map<string, variable_value>::iterator k = begin();
for (map<string, variable_value>::const_iterator k = begin();
k != end();
++k)
{
Expand Down