PrevUpHomeNext

c++ traits type traits - c++ Unsilice


Created on Oct 26, 2024

c++ traits type traits

Think of a trait as a small object whose main purpose is to carry information used by another object or algorithm to determine "policy" or "implementation details".

- Bjarne Stroustrup (link)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Type traits are an intelligency skill of c++ template metaprogramming that give you the ability to inspect, fetch, transform and use the properties (traits) of types.

c++ Examples

static_assert(std::is_floating_point<std::float16_t>::value);
static_assert(std::is_floating_point_v<std::float16_t>);

std::cout << std::boolalpha << std::is_floating_point_v<std::float16_t> << std::endl;	// true
static_assert( ! std::is_floating_point_v<std::string>);

std::cout << std::boolalpha << std::is_floating_point_v<std::string> << std::endl;	// false

See Also

cppreference <type_traits>

Back

Up

Helpful

How To Dig A Hole

How To Ride A Tiger

Hospital

Long Duck

wtgo.top

Role

+

Github:
https://github.com/cppfx/cpphtgt

+

Powered by:
B2 Build | boost quickbook

+

Donate

+

@cppfx.xyz


















PrevUpHomeNext