Cbeam
Loading...
Searching...
No Matches
cbeam::convert::has_insertion_operator< T, typename > Struct Template Reference

The has_insertion_operator trait provides static meta-information about whether a type T has overloaded the operator<< for insertion into an output stream. More...

#include <string.hpp>

Inheritance diagram for cbeam::convert::has_insertion_operator< T, typename >:
Collaboration diagram for cbeam::convert::has_insertion_operator< T, typename >:

Detailed Description

template<typename T, typename = void>
struct cbeam::convert::has_insertion_operator< T, typename >

The has_insertion_operator trait provides static meta-information about whether a type T has overloaded the operator<< for insertion into an output stream.

This trait is useful for template metaprogramming and generic programming, allowing you to write code that works differently depending on whether a type can be streamed or not.

Template Parameters:

  • T: The type to be checked for the existence of an overload for operator<<.
  • U: (optional) An unused template parameter used to enable SFINAE (Substitution Failure Is Not An Error).

Member Types:

  • value: A static constant bool member that is true if and only if T has an overload for operator<<, and false otherwise.

Specializations:

  • The primary template is std::false_type, indicating that by default, types do not have an overload for operator<<.
  • A template specialization exists for types T for which a valid overload for operator<< is found. This specialization uses std::void_t<decltype(std::declval<std::ostream&>() << std::declval<T>())> to ensure that the overload is actually callable.

Example Usage:

template <typename T>
void print_value(const T& value) {
std::cout << value;
} else {
// Handle types without an insertion operator here...
}
}
The has_insertion_operator trait provides static meta-information about whether a type T has overload...
Definition string.hpp:260

See also:

  • std::ostream
  • operator<<
  • std::enable_if
  • std::declval
  • std::void_t

The documentation for this struct was generated from the following file: