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

Role

Powered by - B2 Build | boost quickbook | I2Pd

====

cppfx.i2p

cppfxjjm5bgqx2cepvisfcy4zz4ystzxxh36mtuvqm2jp5g6rb7a.b32.i2p


PrevUpHomeNext