mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-25 06:46:10 +01:00
Enable moving Opts into Parser
This also required keeping the reference type in the fluent interface for Opts. Removes another ~40 allocations.
This commit is contained in:
parent
c57e349d1d
commit
5d5f42f99b
@ -495,10 +495,14 @@ namespace Catch {
|
|||||||
m_ref( std::make_shared<BoundLambda<LambdaT>>( ref ) ),
|
m_ref( std::make_shared<BoundLambda<LambdaT>>( ref ) ),
|
||||||
m_hint( hint ) {}
|
m_hint( hint ) {}
|
||||||
|
|
||||||
auto operator()( StringRef description ) -> DerivedT& {
|
DerivedT& operator()( StringRef description ) & {
|
||||||
m_description = description;
|
m_description = description;
|
||||||
return static_cast<DerivedT&>( *this );
|
return static_cast<DerivedT&>( *this );
|
||||||
}
|
}
|
||||||
|
DerivedT&& operator()( StringRef description ) && {
|
||||||
|
m_description = description;
|
||||||
|
return static_cast<DerivedT&&>( *this );
|
||||||
|
}
|
||||||
|
|
||||||
auto optional() -> DerivedT& {
|
auto optional() -> DerivedT& {
|
||||||
m_optionality = Optionality::Optional;
|
m_optionality = Optionality::Optional;
|
||||||
@ -567,10 +571,14 @@ namespace Catch {
|
|||||||
Opt( T& ref, StringRef hint ):
|
Opt( T& ref, StringRef hint ):
|
||||||
ParserRefImpl( ref, hint ) {}
|
ParserRefImpl( ref, hint ) {}
|
||||||
|
|
||||||
auto operator[](std::string const& optName) -> Opt& {
|
Opt& operator[]( std::string const& optName ) & {
|
||||||
m_optNames.push_back(optName);
|
m_optNames.push_back(optName);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
Opt&& operator[]( std::string const& optName ) && {
|
||||||
|
m_optNames.push_back( optName );
|
||||||
|
return CATCH_MOVE(*this);
|
||||||
|
}
|
||||||
|
|
||||||
Detail::HelpColumns getHelpColumns() const;
|
Detail::HelpColumns getHelpColumns() const;
|
||||||
|
|
||||||
@ -628,21 +636,25 @@ namespace Catch {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto operator|=(Opt const& opt) -> Parser& {
|
friend Parser& operator|=( Parser& p, Opt const& opt ) {
|
||||||
m_options.push_back(opt);
|
p.m_options.push_back( opt );
|
||||||
return *this;
|
return p;
|
||||||
|
}
|
||||||
|
friend Parser& operator|=( Parser& p, Opt&& opt ) {
|
||||||
|
p.m_options.push_back( CATCH_MOVE(opt) );
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
Parser& operator|=(Parser const& other);
|
Parser& operator|=(Parser const& other);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
friend Parser operator|(Parser const& p, T const& rhs) {
|
friend Parser operator|( Parser const& p, T&& rhs ) {
|
||||||
return Parser( p ) |= rhs;
|
return Parser( p ) |= CATCH_FORWARD(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
friend Parser operator|( Parser&& p, T const& rhs ) {
|
friend Parser operator|( Parser&& p, T&& rhs ) {
|
||||||
p |= rhs;
|
p |= CATCH_FORWARD(rhs);
|
||||||
return CATCH_MOVE(p);
|
return CATCH_MOVE(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user