4.0.0
Freundlich's C++ toolkit
Classes | Macros | Typedefs | Enumerations | Functions | Variables
fcppt.various

Description

Documents smaller features that do not warrant their own modules.

Classes

class  fcppt::cyclic_iterator< ContainerIterator >
 An iterator adaptor that cycles through a range. More...
 
class  fcppt::function< Ret(Args...)>
 A function object that cannot be null. More...
 
struct  fcppt::identity
 The identity function. More...
 
class  fcppt::int_iterator< Int >
 An iterator over integers. More...
 
class  fcppt::int_range< Int >
 A forward range over integers. More...
 
struct  fcppt::is_recursive< Type >
 Tests if a type is an fcppt::recursive. More...
 
struct  fcppt::no_init
 A dummy struct to use a constructor that does not initialize. More...
 
struct  fcppt::overloaded< Types >
 Overloads multiple lambdas. More...
 
class  fcppt::recursive< Type >
 Turns an incomplete type into a complete one, allowing recursion. More...
 
struct  fcppt::tag< Type >
 A value for a type name. More...
 
struct  fcppt::unit
 The unit data type. More...
 

Macros

#define FCPPT_ASSERT_COMPLETE(type)
 Assert at compile time that a type is complete. More...
 
#define FCPPT_CHAR_LITERAL(_type, _literal)
 A char or wchar_t literal depending on a type. More...
 
#define FCPPT_CHECK_LITERAL_CONVERSION(dest, source)
 Checks if a literal conversion is safe. More...
 
#define FCPPT_MAIN   FCPPT_DETAIL_MAIN
 The name of the main function. More...
 
#define FCPPT_NONCOPYABLE(classname)   FCPPT_DETAIL_NONCOPYABLE(classname)
 Makes a class noncopyable. More...
 
#define FCPPT_NONMOVABLE(classname)
 Makes a class nonmovable. More...
 
#define FCPPT_STRING_LITERAL(_type, _literal)
 A char or wchar_t string literal depending on a type. More...
 
#define FCPPT_USE(name)   static_cast<void>(name)
 Uses an argument. More...
 

Typedefs

using fcppt::args_char = fcppt::detail::args_char
 The char type of the main function. More...
 
using fcppt::args_range = fcppt::iterator::range< fcppt::args_vector::const_iterator >
 A view over command line arguments. More...
 
using fcppt::args_vector = std::vector< fcppt::string >
 A vector of command line arguments. More...
 
template<typename Arg >
using fcppt::deref_type = decltype(fcppt::deref(std::declval< Arg & >()))
 The type of fcppt::deref. More...
 
using fcppt::major_version = fcppt::version_integral_c< FCPPT_VERSION/(fcppt::detail::version_power *fcppt::detail::version_power)>
 fcppt's major version More...
 
using fcppt::micro_version = fcppt::version_integral_c< FCPPT_VERSION % fcppt::detail::version_power >
 fcppt's micro version More...
 
using fcppt::minor_version = fcppt::version_integral_c<(FCPPT_VERSION/fcppt::detail::version_power) % fcppt::detail::version_power >
 fcppt's minor version More...
 
template<typename Type , typename Arg >
using fcppt::move_if_rvalue_type = decltype(fcppt::move_if_rvalue< Type >(std::declval< Arg >()))
 Type of fcppt::move_if_rvalue. More...
 
using fcppt::optional_error_code = fcppt::optional::object< std::error_code >
 An optional error code. More...
 
template<typename Type >
using fcppt::tag_type = typename fcppt::detail::tag_type< std::remove_cvref_t< Type > >::type
 Extracts the type of fcppt::tag. More...
 
using fcppt::version_int = unsigned long
 The int type to use for a version component. More...
 
template<fcppt::version_int Value>
using fcppt::version_integral_c = std::integral_constant< fcppt::version_int, Value >
 An integral constant for a version component. More...
 

Enumerations

enum class  fcppt::loop { fcppt::loop::break_ , fcppt::loop::continue_ }
 Denotes a loop control statement. More...
 

Functions

template<typename T >
fcppt::absurd ()
 The polymorphic terminate function. More...
 
FCPPT_DETAIL_SYMBOL fcppt::args_vector fcppt::args (int argc, fcppt::args_char const *const *argv)
 Copy main arguments into a container. More...
 
FCPPT_DETAIL_SYMBOL fcppt::args_vector fcppt::args_from_second (int argc, fcppt::args_char const *const *argv)
 Copy main arguments into a container, starting from the second. More...
 
template<typename If , typename Then >
std::invoke_result_t< If > fcppt::cond (bool const _conditional, If const &_if, Then const &_then)
 Functional if-then-else. More...
 
template<typename Type >
fcppt::detail::const_< Type > fcppt::const_ (Type _value)
 Function returning a constant. More...
 
template<typename Type >
Type fcppt::copy (Type const &_value)
 Copies a value. More...
 
template<typename Arg >
decltype(auto) fcppt::deref (Arg &_arg)
 Dereferences an object. More...
 
FCPPT_DETAIL_SYMBOL fcppt::optional_std_string fcppt::getenv (std::string_view)
 Gets an optional value from the environment. More...
 
template<typename Type >
std::size_t fcppt::hash (Type const &_value)
 Calls std::hash. More...
 
std::size_t fcppt::hash_combine (std::size_t const _hash_old, std::size_t const _hash_new)
 Combines two hashes. More...
 
template<typename Ret , typename... Args>
fcppt::function< Ret(Args...)> fcppt::make_function (Ret(&_function)(Args...))
 Creates an fcppt::function. More...
 
template<typename Int >
fcppt::int_range< Int > fcppt::make_int_range (Int const _begin, Int const _end)
 Creates a forward integer range. More...
 
template<typename Int >
fcppt::int_range< Int > fcppt::make_int_range_count (Int const _count)
 Creates a forward integer range starting at zero. More...
 
FCPPT_DETAIL_SYMBOL fcppt::optional_error_code fcppt::make_optional_error_code (std::error_code const &error)
 Creates an optional error code. More...
 
template<typename Type >
fcppt::recursive< std::remove_cvref_t< Type > > fcppt::make_recursive (Type &&_value)
 Creates an fcppt::recursive. More...
 
template<typename Type >
Type fcppt::move_clear (Type &_value)
 Moves out of a value and clears it. More...
 
template<bool Cond, typename Arg >
decltype(auto) fcppt::move_if (Arg &&_arg)
 Moves an object if a condition is true. More...
 
template<typename Type , typename Arg >
decltype(auto) fcppt::move_if_rvalue (Arg &&_arg)
 Moves an object if a type is an rvalue. More...
 
constexpr bool fcppt::not_ (bool const _value)
 Boolean not. More...
 
template<typename Arg >
fcppt::detail::output< Arg > fcppt::output (Arg const &_arg)
 Outputs an object. More...
 
template<typename... Args>
fcppt::overloaded< std::remove_cvref_t< Args >... > fcppt::overload (Args &&..._args)
 Creates an overloaded lambda. More...
 
template<typename Type >
bool fcppt::operator== (fcppt::recursive< Type > const &_left, fcppt::recursive< Type > const &_right)
 Compares two fcppt::recursive for equality. More...
 
template<typename Type >
bool fcppt::operator!= (fcppt::recursive< Type > const &_left, fcppt::recursive< Type > const &_right)
 Compares two fcppt::recursive for inequality. More...
 
template<typename MaxIndex , typename Index , typename Function , typename FailFunction >
decltype(auto) fcppt::runtime_index (Index const _index, Function const &_function, FailFunction const &_fail_function)
 Transforms a runtime index into a an integral constant. More...
 
FCPPT_DETAIL_SYMBOL std::string fcppt::type_name (char const *)
 Returns a demangled type name if possible. More...
 
FCPPT_DETAIL_SYMBOL std::string fcppt::type_name_from_index (std::type_index const &)
 Returns a demangled type name if possible. More...
 
FCPPT_DETAIL_SYMBOL std::string fcppt::type_name_from_info (std::type_info const &)
 Returns a demangled type name if possible. More...
 
bool fcppt::operator== (fcppt::unit const &, fcppt::unit const &)
 Compares units for equality. More...
 
bool fcppt::operator!= (fcppt::unit const &, fcppt::unit const &)
 Compares units for inequality. More...
 
template<typename Ch , typename Traits >
std::basic_ostream< Ch, Traits > & fcppt::operator<< (std::basic_ostream< Ch, Traits > &_stream, fcppt::unit const &)
 Outputs a unit to a basic_ostream. More...
 
FCPPT_DETAIL_SYMBOL std::string fcppt::version_string ()
 fcppt's version as a string More...
 
FCPPT_OPTIONS_DETAIL_SYMBOL fcppt::string fcppt::options::indent (fcppt::string &&)
 Indents every line of a string once. More...
 

Variables

template<typename Type , typename Iterator >
decltype(fcppt::detail::move_iterator_if_rvalue< Type >(std::declval< Iterator const & >())) fcppt::move_iterator_if_rvalue (Iterator const &_iterator)
 Makes a move iterator if a type is an rvalue. More...
 

Macro Definition Documentation

◆ FCPPT_ASSERT_COMPLETE

#define FCPPT_ASSERT_COMPLETE (   type)
Value:
static_assert( \
sizeof(type) > 0, /* NOLINT(bugprone-sizeof-expression)*/ \
"Type must be complete")

Assert at compile time that a type is complete.

In some cases, a type must be complete, which bascially means that it is not void and if it is a class, the definition must already be known. For example, delete has undefined behaviour if it is invoked on a type that is not complete but has a non trivial destructor.

This macro generates a compile time error if a type is not complete. An example of its usage is shown below.

template <typename T>
void std_delete(T *const _param)
{
delete _param; // NOLINT(cppcoreguidelines-owning-memory)
}

◆ FCPPT_CHAR_LITERAL

#define FCPPT_CHAR_LITERAL (   _type,
  _literal 
)
Value:
fcppt::detail::char_literal<_type>(FCPPT_DETAIL_MAKE_CHAR_LITERALS( \

A char or wchar_t literal depending on a type.

If _type is char, then the literal will be of type char. If _type is wchar_t, then the literal will be of type wchar_t.

Parameters
_typeMust be char or wchar_t.
_literalMust be a char literal.

◆ FCPPT_CHECK_LITERAL_CONVERSION

#define FCPPT_CHECK_LITERAL_CONVERSION (   dest,
  source 
)
Value:
static_assert( \
!std::is_same<source, bool>::value && \
!(std::is_integral<dest>::value && std::is_floating_point<source>::value), \
"A literal conversion from bool, or from floating point to int is not allowed!")

Checks if a literal conversion is safe.

source must not be a bool or if dest is integral, then source must not be floating-point.

◆ FCPPT_MAIN

#define FCPPT_MAIN   FCPPT_DETAIL_MAIN

The name of the main function.

Windows uses wmain instead of main for Unicode applications. The type of this function is int (int,fcppt::args_char **).

Note
This must be used together with FCPPT_UTILS_MAIN_COMPILE_OPTIONS and FCPPT_UTILS_MAIN_LINK_LIBS.

◆ FCPPT_NONCOPYABLE

#define FCPPT_NONCOPYABLE (   classname)    FCPPT_DETAIL_NONCOPYABLE(classname)

Makes a class noncopyable.

Makes the class called classname noncopyable. The macro must be placed inside the class definition and called with the name of the class. It deletes the copy constructor and the assignment operator. The idea is that the user still implements a move constructor and a move assignment operator. If this is not desired, use FCPPT_NONMOVABLE instead.

class test_noncopyable
{
FCPPT_NONCOPYABLE(test_noncopyable);
public:
test_noncopyable() : ptr_(new int(1)) {}
test_noncopyable(test_noncopyable &&_other) noexcept : ptr_{_other.ptr_}
{
_other.ptr_ = nullptr;
}
test_noncopyable &operator=(test_noncopyable &&_other) noexcept
{
if (&_other == this)
{
return *this;
}
ptr_ = _other.ptr_;
_other.ptr_ = nullptr;
return *this;
}
~test_noncopyable() noexcept { delete ptr_; }
private:
int *ptr_;
};
Parameters
classnameThe name of the class.

◆ FCPPT_NONMOVABLE

#define FCPPT_NONMOVABLE (   classname)
Value:
FCPPT_DETAIL_NONCOPYABLE(classname); \
FCPPT_DETAIL_NONMOVABLE(classname)

Makes a class nonmovable.

Makes the class called classname nonmovable and noncopyable. The macro must be placed inside the class definition and called with the name of the class. It deletes the move constructor, the copy constructor, the move assignment operator and the copy assignment operator.

Parameters
classnameThe name of the class.

◆ FCPPT_STRING_LITERAL

#define FCPPT_STRING_LITERAL (   _type,
  _literal 
)
Value:
fcppt::detail::string_literal<_type>(FCPPT_DETAIL_MAKE_CHAR_LITERALS( \

A char or wchar_t string literal depending on a type.

If _type is char, then the literal will be of type char const *. If _type is wchar_t, then the literal will be of type wchar_t const *.

Parameters
_typeMust be char or wchar_t.
_literalMust be a string literal.

◆ FCPPT_USE

#define FCPPT_USE (   name)    static_cast<void>(name)

Uses an argument.

This is useful in situations where an argument is only used for its type.

Typedef Documentation

◆ args_char

using fcppt::args_char = typedef fcppt::detail::args_char

The char type of the main function.

◆ args_range

using fcppt::args_range = typedef fcppt::iterator::range<fcppt::args_vector::const_iterator>

A view over command line arguments.

◆ args_vector

using fcppt::args_vector = typedef std::vector<fcppt::string>

A vector of command line arguments.

◆ deref_type

template<typename Arg >
using fcppt::deref_type = typedef decltype(fcppt::deref(std::declval<Arg &>()))

The type of fcppt::deref.

◆ major_version

using fcppt::major_version = typedef fcppt::version_integral_c< FCPPT_VERSION / (fcppt::detail::version_power * fcppt::detail::version_power)>

fcppt's major version

◆ micro_version

using fcppt::micro_version = typedef fcppt::version_integral_c<FCPPT_VERSION % fcppt::detail::version_power>

fcppt's micro version

◆ minor_version

using fcppt::minor_version = typedef fcppt::version_integral_c< (FCPPT_VERSION / fcppt::detail::version_power) % fcppt::detail::version_power>

fcppt's minor version

◆ move_if_rvalue_type

template<typename Type , typename Arg >
using fcppt::move_if_rvalue_type = typedef decltype(fcppt::move_if_rvalue<Type>(std::declval<Arg>()))

◆ optional_error_code

using fcppt::optional_error_code = typedef fcppt::optional::object<std::error_code>

An optional error code.

◆ tag_type

template<typename Type >
using fcppt::tag_type = typedef typename fcppt::detail::tag_type<std::remove_cvref_t<Type> >::type

Extracts the type of fcppt::tag.

◆ version_int

using fcppt::version_int = typedef unsigned long

The int type to use for a version component.

◆ version_integral_c

template<fcppt::version_int Value>
using fcppt::version_integral_c = typedef std::integral_constant<fcppt::version_int, Value>

An integral constant for a version component.

Enumeration Type Documentation

◆ loop

enum class fcppt::loop
strong

Denotes a loop control statement.

Used by various algorithms that need the ability to break out of a loop early.

Enumerator
break_ 
continue_ 

Function Documentation

◆ absurd()

template<typename T >
T fcppt::absurd ( )
inline

The polymorphic terminate function.

Terminates the program but can be used where an expression of any type is required.

◆ args()

FCPPT_DETAIL_SYMBOL fcppt::args_vector fcppt::args ( int  argc,
fcppt::args_char const *const *  argv 
)

Copy main arguments into a container.

This function is only useful for command line arguments received in main. To handle Windows arguments, see the GetCommandLine function.

◆ args_from_second()

FCPPT_DETAIL_SYMBOL fcppt::args_vector fcppt::args_from_second ( int  argc,
fcppt::args_char const *const *  argv 
)

Copy main arguments into a container, starting from the second.

◆ cond()

template<typename If , typename Then >
std::invoke_result_t< If > fcppt::cond ( bool const  _conditional,
If const &  _if,
Then const &  _then 
)
inline

Functional if-then-else.

Unlike the ? : operator, this function does no implicit conversions.

The functions If and Then must return the same type R.

Template Parameters
IfA function callable as R ().
ThenA function callable as R ().

◆ const_()

template<typename Type >
fcppt::detail::const_< Type > fcppt::const_ ( Type  _value)
inline

Function returning a constant.

◆ copy()

template<typename Type >
Type fcppt::copy ( Type const &  _value)
inline

Copies a value.

This function is useful in case you need to make an explicit copy of a value but don't want to write down its type.

◆ deref()

template<typename Arg >
decltype(auto) fcppt::deref ( Arg &  _arg)
inline

Dereferences an object.

Calls fcppt::deref_impl::execute to dereference _arg.

◆ getenv()

FCPPT_DETAIL_SYMBOL fcppt::optional_std_string fcppt::getenv ( std::string_view  )

Gets an optional value from the environment.

Warning
This function calls std::getenv which is not thread-safe. You must ensure that this function is not called concurrently with any function that modifies the environment.

◆ hash()

template<typename Type >
std::size_t fcppt::hash ( Type const &  _value)
inline

Calls std::hash.

◆ hash_combine()

std::size_t fcppt::hash_combine ( std::size_t const  _hash_old,
std::size_t const  _hash_new 
)
inline

Combines two hashes.

◆ indent()

FCPPT_OPTIONS_DETAIL_SYMBOL fcppt::string fcppt::options::indent ( fcppt::string &&  )

Indents every line of a string once.

◆ make_function()

template<typename Ret , typename... Args>
fcppt::function< Ret(Args...)> fcppt::make_function ( Ret(&)(Args...)  _function)

Creates an fcppt::function.

◆ make_int_range()

template<typename Int >
fcppt::int_range< Int > fcppt::make_int_range ( Int const  _begin,
Int const  _end 
)
inline

Creates a forward integer range.

Creates the forward integer range [_begin, _end).

Parameters
_beginThe first element in the range
_endOne past the last element of the range

◆ make_int_range_count()

template<typename Int >
fcppt::int_range< Int > fcppt::make_int_range_count ( Int const  _count)
inline

Creates a forward integer range starting at zero.

Creates the forward integer range [0, _count). The purpose of this class is to create integer ranges over integer-like types (not just fundamental integers), for example strong typedefs of integers.

Parameters
_countThe number of elements in the range

◆ make_optional_error_code()

FCPPT_DETAIL_SYMBOL fcppt::optional_error_code fcppt::make_optional_error_code ( std::error_code const &  error)

Creates an optional error code.

If error has an error value, then it is returned as an optional. Otherwise, the empty optional is returned.

◆ make_recursive()

template<typename Type >
fcppt::recursive< std::remove_cvref_t< Type > > fcppt::make_recursive ( Type &&  _value)

Creates an fcppt::recursive.

◆ move_clear()

template<typename Type >
Type fcppt::move_clear ( Type &  _value)

Moves out of a value and clears it.

Certain types can be moved out of but are then left in an unspecific state that only allows them to be destroyed or assigned. This function first moves out of the value and then assigns a default constructed value. For example, this function can be used to move out of a container and leave an empty container behind.

Template Parameters
TypeMust be movable and have a default constructor.

◆ move_if()

template<bool Cond, typename Arg >
decltype(auto) fcppt::move_if ( Arg &&  _arg)
inline

Moves an object if a condition is true.

Moves _arg if Cond is true or Arg is an rvalue.

◆ move_if_rvalue()

template<typename Type , typename Arg >
decltype(auto) fcppt::move_if_rvalue ( Arg &&  _arg)
inline

Moves an object if a type is an rvalue.

Moves _arg if Type is an rvalue or if Arg is an rvalue. The behavior is similar to std::forward except that this function depends on two types instead of one. This can be useful in situations where you want to move a member if the surrounding object is an rvalue.

◆ not_()

constexpr bool fcppt::not_ ( bool const  _value)
inlineconstexpr

Boolean not.

This function is a replacement for !.

◆ operator!=() [1/2]

template<typename Type >
bool fcppt::operator!= ( fcppt::recursive< Type > const &  _left,
fcppt::recursive< Type > const &  _right 
)

Compares two fcppt::recursive for inequality.

◆ operator!=() [2/2]

bool fcppt::operator!= ( fcppt::unit const &  ,
fcppt::unit const &   
)
inline

Compares units for inequality.

◆ operator<<()

template<typename Ch , typename Traits >
std::basic_ostream< Ch, Traits > & fcppt::operator<< ( std::basic_ostream< Ch, Traits > &  _stream,
fcppt::unit const &   
)
inline

Outputs a unit to a basic_ostream.

◆ operator==() [1/2]

template<typename Type >
bool fcppt::operator== ( fcppt::recursive< Type > const &  _left,
fcppt::recursive< Type > const &  _right 
)

Compares two fcppt::recursive for equality.

◆ operator==() [2/2]

bool fcppt::operator== ( fcppt::unit const &  ,
fcppt::unit const &   
)
inline

Compares units for equality.

◆ output()

template<typename Arg >
fcppt::detail::output< Arg > fcppt::output ( Arg const &  _arg)
inline

Outputs an object.

Calls fcppt::output_impl::execute to output _arg. The default implementation uses operator<< .

◆ overload()

template<typename... Args>
fcppt::overloaded< std::remove_cvref_t< Args >... > fcppt::overload ( Args &&...  _args)

Creates an overloaded lambda.

◆ runtime_index()

template<typename MaxIndex , typename Index , typename Function , typename FailFunction >
decltype(auto) fcppt::runtime_index ( Index const  _index,
Function const &  _function,
FailFunction const &  _fail_function 
)
inline

Transforms a runtime index into a an integral constant.

Passes _index as an integral constant to _function if _index is less than MaxIndex::value, and returns its result. Otherwise, the result of _fail_function is returned.

Template Parameters
IndexAn unsigned integer type.
MaxIndexAn integral constant with element type Index.
FunctionA function callable as R (std::integral_constant<Index,N>) for every N of type Index, where R is the result type.
FailFunctionA function callable as R(), where R is the result type.

◆ type_name()

FCPPT_DETAIL_SYMBOL std::string fcppt::type_name ( char const *  )

Returns a demangled type name if possible.

◆ type_name_from_index()

FCPPT_DETAIL_SYMBOL std::string fcppt::type_name_from_index ( std::type_index const &  )

Returns a demangled type name if possible.

◆ type_name_from_info()

FCPPT_DETAIL_SYMBOL std::string fcppt::type_name_from_info ( std::type_info const &  )

Returns a demangled type name if possible.

◆ version_string()

FCPPT_DETAIL_SYMBOL std::string fcppt::version_string ( )

fcppt's version as a string

Variable Documentation

◆ move_iterator_if_rvalue

template<typename Type , typename Iterator >
decltype(fcppt::detail::move_iterator_if_rvalue< Type >(std::declval< Iterator const & >())) fcppt::move_iterator_if_rvalue(Iterator const &_iterator) ( Iterator const &  _iterator)
inline

Makes a move iterator if a type is an rvalue.

Makes a move iterator out of _iterator iff Type is an rvalue.