Skip to content
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

Introduce variable_value::as_optional<>() #87

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

matwey
Copy link

@matwey matwey commented Nov 22, 2019

In some cases, optional<> types are used to specify missed input parameters in
functions. It may be the case when missed parameter has meaning 'unknown'
rather than 'default' and requires different behaviour.

Introduce convenient interface for program_options to write code as the
following:

const auto opt = va['opt'].as_optional<T>();

as_optional() returns the value when stored type is T,
empty optional when variable_value is empty,
or raise bad_cast exception when stored type is other than T (as in case of
as()).

The latter case is considered as a kind of logic/runtime error since the user
is supposed to know which type he expects that the variable has.

In some cases, optional<> types are used to specify missed input parameters in
functions. It may be the case when missed parameter has meaning 'unknown'
rather than 'default' and requires different behaviour.

Introduce convenient interface for program_options to write code as the
following:

    const auto opt = va['opt'].as_optional<T>();

as_optional<T>() returns the value when stored type is T,
empty optional<T> when variable_value is empty,
or raise bad_cast exception when stored type is other than T (as in case of
as<T>()).

The latter case is considered as a kind of logic/runtime error since the user
is supposed to know which type he expects that the variable has.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant