@ -105,11 +105,9 @@ namespace llarp
constexpr bool is_default_array < U & > = is_default_array < remove_cvref_t < U > > ;
constexpr bool is_default_array < U & > = is_default_array < remove_cvref_t < U > > ;
template < typename T , typename Option >
template < typename T , typename Option >
constexpr bool is_option =
constexpr bool is_option = std : : is_base_of_v < option_flag , remove_cvref_t < Option > >
std : : is_base_of_v <
or std : : is_same_v < Comment , Option > or is_default < Option > or is_default_array < Option >
option_flag ,
or std : : is_invocable_v < remove_cvref_t < Option > , T > ;
remove_cvref_t <
Option > > or std : : is_same_v < Comment , Option > or is_default < Option > or is_default_array < Option > or std : : is_invocable_v < remove_cvref_t < Option > , T > ;
} // namespace config
} // namespace config
/// A base class for specifying config options and their constraints. The basic to/from string
/// A base class for specifying config options and their constraints. The basic to/from string
@ -298,7 +296,12 @@ namespace llarp
std : : vector < std : : string > def_strs ;
std : : vector < std : : string > def_strs ;
def_strs . reserve ( defaultValues . size ( ) ) ;
def_strs . reserve ( defaultValues . size ( ) ) ;
for ( const auto & v : defaultValues )
for ( const auto & v : defaultValues )
def_strs . push_back ( fmt : : format ( " {} " , v ) ) ;
{
if constexpr ( std : : is_same_v < bool , T > )
def_strs . push_back ( fmt : : format ( " {} " , ( bool ) v ) ) ;
else
def_strs . push_back ( fmt : : format ( " {} " , v ) ) ;
}
return def_strs ;
return def_strs ;
}
}
}
}
@ -308,8 +311,7 @@ namespace llarp
{
{
if ( not multiValued and parsedValues . size ( ) > 0 )
if ( not multiValued and parsedValues . size ( ) > 0 )
{
{
throw std : : invalid_argument {
throw std : : invalid_argument { fmt : : format ( " duplicate value for {} " , name ) } ;
fmt : : format ( " duplicate value for {}, previous value: {} " , name , parsedValues [ 0 ] ) } ;
}
}
parsedValues . emplace_back ( fromString ( input ) ) ;
parsedValues . emplace_back ( fromString ( input ) ) ;
@ -329,8 +331,7 @@ namespace llarp
iss > > t ;
iss > > t ;
if ( iss . fail ( ) )
if ( iss . fail ( ) )
throw std : : invalid_argument { fmt : : format ( " {} is not a valid {} " , input , typeid ( T ) . name ( ) ) } ;
throw std : : invalid_argument { fmt : : format ( " {} is not a valid {} " , input , typeid ( T ) . name ( ) ) } ;
else
return t ;
return t ;
}
}
}
}
@ -342,7 +343,12 @@ namespace llarp
std : : vector < std : : string > result ;
std : : vector < std : : string > result ;
result . reserve ( parsedValues . size ( ) ) ;
result . reserve ( parsedValues . size ( ) ) ;
for ( const auto & v : parsedValues )
for ( const auto & v : parsedValues )
result . push_back ( fmt : : format ( " {} " , v ) ) ;
{
if constexpr ( std : : is_same_v < bool , T > )
result . push_back ( fmt : : format ( " {} " , ( bool ) v ) ) ;
else
result . push_back ( fmt : : format ( " {} " , v ) ) ;
}
return result ;
return result ;
}
}