eswitch-v5
Advanced counterpart for switch statement in C++
Main-components

Description

Classes

class  eswitch_v5::condition< CmpOperator, TIndex, CaseEntry >
 Compares value with corresponding entry in std::tuple. More...
 
struct  eswitch_v5::condition_with_predicate< Cnd, Func >
 
class  eswitch_v5::conditions< LogicalOperator, Cnds >
 Container which holds arbitrary number of condition. More...
 
class  eswitch_v5::eswitch_impl< Args >
 Accept arbitrary number of Case's and test each of them sequentially. If match was found then executes Case body, also based on Case falling option decides whether to execute next body or finish work. More...
 
struct  eswitch_v5::Fallthrough
 
struct  eswitch_v5::is< T >
 Used to match for type of active entry in std::any, std::variant<...> and polymorphic types. More...
 
class  eswitch_v5::predicate_condition< TPred, Is >
 

Enumerations

enum  eswitch_v5::Comparison_operators {
  eswitch_v5::Comparison_operators::equal, eswitch_v5::Comparison_operators::not_equal, eswitch_v5::Comparison_operators::greater, eswitch_v5::Comparison_operators::greater_or_equal,
  eswitch_v5::Comparison_operators::less, eswitch_v5::Comparison_operators::less_or_equal
}
 
enum  eswitch_v5::Logical_operators { eswitch_v5::Logical_operators::and_, eswitch_v5::Logical_operators::or_ }
 

Functions

template<typename ... Args>
static constexpr auto eswitch_v5::any_from (Args &&... args)
 Helper function which allows to find if something is within the list( passed arguments ). More...
 
template<Condition Cnd>
static constexpr auto eswitch_v5::case_ (Cnd &&cnd)
 
template<typename ... Ts>
static constexpr auto eswitch_v5::case_ (Ts &&... values)
 
template<typename P , std::size_t ... I, Index Idx>
predicate_condition< P, I..., Idx::eswitch_index > eswitch_v5::compose_new_predicate_condition_type (const predicate_condition< P, I... > &, Idx)
 
template<StdPair T>
static constexpr auto eswitch_v5::eswitch (T &&pair)
 This overload expand std::pair. Simplifies following form eswitch( pair.first, pair.second ) to eswitch( pair ). Moreover there is similar overload for std::tuple. More...
 
template<typename ... Ts>
static constexpr auto eswitch_v5::eswitch (Ts &&... ts)
 This function is responsible for passing arguments for class eswitch_impl with overloaded operator(), which accepts arbitrary number of Case's. More...
 
template<Index Idx, typename T >
constexpr auto eswitch_v5::operator!= (Idx &&, T &&rhv)
 
auto eswitch_v5::operator""_r (const char *rgx, const std::size_t sz)
 User-defined literals for std::regex. More...
 
template<Condition T, Callable Func>
static constexpr auto eswitch_v5::operator% (T &&cnd, Func &&f)
 
template<Condition Cnd1, Condition Cnd2>
static constexpr auto eswitch_v5::operator&& (Cnd1 &&cnd1, Cnd2 &&cnd2)
 
template<Condition ... Cnds, Condition Cnd>
static constexpr auto eswitch_v5::operator&& (conditions< Logical_operators::and_, Cnds... > &&cnds, Cnd &&cnd)
 
template<IsNotCndPredicate Pred, Index Idx>
static constexpr auto eswitch_v5::operator, (Pred &&pred, Idx)
 
template<typename R , typename... Args, Index Idx>
static constexpr auto eswitch_v5::operator, (R(*pred)(Args...), Idx)
 
template<Index Idx, typename T >
constexpr auto eswitch_v5::operator< (Idx &&, T &&rhv)
 
template<Index Idx, typename T >
constexpr auto eswitch_v5::operator<= (Idx &&, T &&rhv)
 
template<Index Idx, typename T >
static constexpr auto eswitch_v5::operator== (Idx &&, T &&rhv)
 
template<Index Idx, typename T >
constexpr auto eswitch_v5::operator> (Idx &&, T &&rhv)
 
template<Index Idx, typename T >
constexpr auto eswitch_v5::operator>= (Idx &&, T &&rhv)
 
template<typename Cnd , ReturnValueNoneVoid Func>
static constexpr auto eswitch_v5::operator^ (condition_with_predicate< Cnd, Func > &&cp, const Fallthrough &)
 
template<Condition Cnd1, Condition Cnd2>
static constexpr auto eswitch_v5::operator|| (Cnd1 &&cnd1, Cnd2 &&cnd2)
 
template<Condition ... Cnds, Condition Cnd>
static constexpr auto eswitch_v5::operator|| (conditions< Logical_operators::or_, Cnds... > &&cnds, Cnd &&cnd)
 

Enumeration Type Documentation

◆ Comparison_operators

#include <eswitch_v5.hpp>

Enumerator
equal 
not_equal 
greater 
greater_or_equal 
less 
less_or_equal 

Definition at line 50 of file eswitch_v5.hpp.

◆ Logical_operators

#include <eswitch_v5.hpp>

Enumerator
and_ 
or_ 

Definition at line 49 of file eswitch_v5.hpp.

49 { and_, or_ };

Function Documentation

◆ any_from()

template<typename ... Args>
static constexpr auto eswitch_v5::any_from ( Args &&...  args)
staticconstexpr

#include <eswitch_v5.hpp>

Helper function which allows to find if something is within the list( passed arguments ).

Definition at line 991 of file eswitch_v5.hpp.

992  {
993  return extension::Any_from_impl( std::forward< Args >( args )... );
994  }

◆ case_() [1/2]

template<Condition Cnd>
static constexpr auto eswitch_v5::case_ ( Cnd &&  cnd)
staticconstexpr

#include <eswitch_v5.hpp>

Definition at line 968 of file eswitch_v5.hpp.

969  {
970  return std::move( cnd );
971  }

◆ case_() [2/2]

template<typename ... Ts>
static constexpr auto eswitch_v5::case_ ( Ts &&...  values)
staticconstexpr

#include <eswitch_v5.hpp>

Definition at line 974 of file eswitch_v5.hpp.

975  {
976  auto lmbd = []< typename T, T ... ints >( std::index_sequence< ints... >&&, auto &&... values )
977  {
978  // I intentionally avoided std::make_tuple, because the former change type of string literals
979  // from "const char[some_size]&" to "const char*" and this significantly impacts the performance.
980  return details::create_indexed_condition< ints... >(
981  std::tuple< Ts... >( std::forward< Ts >( values )... ) );
982  };
983 
984  return lmbd( std::make_index_sequence< sizeof...(Ts) >{},
985  std::forward< Ts >( values )... );
986  }

◆ compose_new_predicate_condition_type()

template<typename P , std::size_t ... I, Index Idx>
predicate_condition< P, I..., Idx::eswitch_index > eswitch_v5::compose_new_predicate_condition_type ( const predicate_condition< P, I... > &  ,
Idx   
)

#include <eswitch_v5.hpp>

◆ eswitch() [1/2]

template<StdPair T>
static constexpr auto eswitch_v5::eswitch ( T &&  pair)
staticconstexpr

#include <eswitch_v5.hpp>

This overload expand std::pair. Simplifies following form eswitch( pair.first, pair.second ) to eswitch( pair ). Moreover there is similar overload for std::tuple.

Definition at line 848 of file eswitch_v5.hpp.

849  {
850  if constexpr( std::is_rvalue_reference_v< T&& > )
851  {
852  return eswitch_impl( std::move( pair.first ), std::move( pair.second ) );
853  }
854  else
855  {
856  return eswitch_impl( pair.first, pair.second );
857  }
858  }

◆ eswitch() [2/2]

template<typename ... Ts>
static constexpr auto eswitch_v5::eswitch ( Ts &&...  ts)
staticconstexpr

#include <eswitch_v5.hpp>

This function is responsible for passing arguments for class eswitch_impl with overloaded operator(), which accepts arbitrary number of Case's.

Definition at line 838 of file eswitch_v5.hpp.

839  {
840  return eswitch_impl( std::forward< Ts >( ts )... );
841  }

◆ operator!=()

template<Index Idx, typename T >
constexpr auto eswitch_v5::operator!= ( Idx &&  ,
T &&  rhv 
)
constexpr

#include <eswitch_v5.hpp>

Definition at line 670 of file eswitch_v5.hpp.

671  {
672  return condition< Comparison_operators::not_equal, std::decay_t< Idx >, T >( std::forward< T >( rhv ) );
673  }

◆ operator""_r()

auto eswitch_v5::operator""_r ( const char *  rgx,
const std::size_t  sz 
)

#include <eswitch_v5.hpp>

User-defined literals for std::regex.

Definition at line 1005 of file eswitch_v5.hpp.

1006  {
1007  return regexter{ std::regex{ rgx } };
1008  }

◆ operator%()

template<Condition T, Callable Func>
static constexpr auto eswitch_v5::operator% ( T &&  cnd,
Func &&  f 
)
staticconstexpr

#include <eswitch_v5.hpp>

Definition at line 894 of file eswitch_v5.hpp.

895  {
896  return condition_with_predicate{ std::move( cnd ), std::move( f ) };
897  }

◆ operator&&() [1/2]

template<Condition Cnd1, Condition Cnd2>
static constexpr auto eswitch_v5::operator&& ( Cnd1 &&  cnd1,
Cnd2 &&  cnd2 
)
staticconstexpr

#include <eswitch_v5.hpp>

Definition at line 645 of file eswitch_v5.hpp.

646  {
647  return conditions< Logical_operators::and_, Cnd1, Cnd2 >( std::move( cnd1 ), std::move( cnd2 ) );
648  }

◆ operator&&() [2/2]

template<Condition ... Cnds, Condition Cnd>
static constexpr auto eswitch_v5::operator&& ( conditions< Logical_operators::and_, Cnds... > &&  cnds,
Cnd &&  cnd 
)
staticconstexpr

#include <eswitch_v5.hpp>

Definition at line 638 of file eswitch_v5.hpp.

639  {
640  return conditions< Logical_operators::and_, Cnds..., Cnd >(
641  std::move( cnds ), std::move( cnd ) );
642  }

◆ operator,() [1/2]

template<IsNotCndPredicate Pred, Index Idx>
static constexpr auto eswitch_v5::operator, ( Pred &&  pred,
Idx  idx 
)
staticconstexpr

#include <eswitch_v5.hpp>

Definition at line 947 of file eswitch_v5.hpp.

948  {
949  return predicate_condition< std::remove_reference_t< Pred >, Idx::eswitch_index >(
950  std::forward< Pred >( pred ) );
951  }

◆ operator,() [2/2]

template<typename R , typename... Args, Index Idx>
static constexpr auto eswitch_v5::operator, ( R(*)(Args...)  pred,
Idx   
)
staticconstexpr

#include <eswitch_v5.hpp>

Definition at line 941 of file eswitch_v5.hpp.

942  {
943  return predicate_condition< R(*)(Args...), Idx::eswitch_index >( pred );
944  }

◆ operator<()

template<Index Idx, typename T >
constexpr auto eswitch_v5::operator< ( Idx &&  ,
T &&  rhv 
)
constexpr

#include <eswitch_v5.hpp>

Definition at line 688 of file eswitch_v5.hpp.

689  {
690  return condition< Comparison_operators::less, std::decay_t< Idx >, T >( std::forward< T >( rhv ) );
691  }

◆ operator<=()

template<Index Idx, typename T >
constexpr auto eswitch_v5::operator<= ( Idx &&  ,
T &&  rhv 
)
constexpr

#include <eswitch_v5.hpp>

Definition at line 694 of file eswitch_v5.hpp.

695  {
696  return condition< Comparison_operators::less_or_equal, std::decay_t< Idx >, T >( std::forward< T >( rhv ) );
697  }

◆ operator==()

template<Index Idx, typename T >
static constexpr auto eswitch_v5::operator== ( Idx &&  ,
T &&  rhv 
)
staticconstexpr

#include <eswitch_v5.hpp>

Definition at line 664 of file eswitch_v5.hpp.

665  {
666  return condition< Comparison_operators::equal, std::decay_t< Idx >, T >( std::forward< T >( rhv ) );
667  }

◆ operator>()

template<Index Idx, typename T >
constexpr auto eswitch_v5::operator> ( Idx &&  ,
T &&  rhv 
)
constexpr

#include <eswitch_v5.hpp>

Definition at line 676 of file eswitch_v5.hpp.

677  {
678  return condition< Comparison_operators::greater, std::decay_t< Idx >, T >( std::forward< T >( rhv ) );
679  }

◆ operator>=()

template<Index Idx, typename T >
constexpr auto eswitch_v5::operator>= ( Idx &&  ,
T &&  rhv 
)
constexpr

#include <eswitch_v5.hpp>

Definition at line 682 of file eswitch_v5.hpp.

683  {
684  return condition< Comparison_operators::greater_or_equal, std::decay_t< Idx >, T >( std::forward< T >( rhv ) );
685  }

◆ operator^()

template<typename Cnd , ReturnValueNoneVoid Func>
static constexpr auto eswitch_v5::operator^ ( condition_with_predicate< Cnd, Func > &&  cp,
const Fallthrough  
)
staticconstexpr

#include <eswitch_v5.hpp>

Definition at line 902 of file eswitch_v5.hpp.

903  {
904  cp.fallthrough = true;
905 
906  return std::move( cp );
907  }

◆ operator||() [1/2]

template<Condition Cnd1, Condition Cnd2>
static constexpr auto eswitch_v5::operator|| ( Cnd1 &&  cnd1,
Cnd2 &&  cnd2 
)
staticconstexpr

#include <eswitch_v5.hpp>

Definition at line 658 of file eswitch_v5.hpp.

659  {
660  return conditions< Logical_operators::or_, Cnd1, Cnd2 >( std::move( cnd1 ), std::move( cnd2 ) );
661  }

◆ operator||() [2/2]

template<Condition ... Cnds, Condition Cnd>
static constexpr auto eswitch_v5::operator|| ( conditions< Logical_operators::or_, Cnds... > &&  cnds,
Cnd &&  cnd 
)
staticconstexpr

#include <eswitch_v5.hpp>

Definition at line 651 of file eswitch_v5.hpp.

652  {
653  return conditions< Logical_operators::or_, Cnds..., Cnd >(
654  std::move( cnds ), std::move( cnd ) );
655  }
std::equal
T equal(T... args)
std::index_sequence
std::tuple
eswitch_v5::Logical_operators::or_
@ or_
eswitch_v5::eswitch_impl
eswitch_impl(Ts &&...) -> eswitch_impl< Ts... >
eswitch_v5::Comparison_operators::not_equal
@ not_equal
eswitch_v5::Comparison_operators::greater
@ greater
eswitch_v5::extension::Any_from_impl
Any_from_impl(Args &&...) -> Any_from_impl< std::common_type_t< std::decay_t< Args >... >, sizeof...(Args) >
eswitch_v5::Comparison_operators::greater_or_equal
@ greater_or_equal
std::regex
eswitch_v5::Comparison_operators::less
@ less
eswitch_v5::details::create_indexed_condition
static constexpr auto create_indexed_condition(Tup &&values)
Definition: eswitch_v5.hpp:348
eswitch_v5::Comparison_operators::less_or_equal
@ less_or_equal
eswitch_v5::condition_with_predicate
condition_with_predicate(T, F) -> condition_with_predicate< T, F >
eswitch_v5::Logical_operators::and_
@ and_