std::is_bounded_array(3)
π std::is_bounded_array(3) π
okay so bestie, welcome to the C++ Standard Library corner of the man pages β this one is std::is_bounded_array and it's genuinely one of the cutest little type traits out there. no cap.
β¨ NAME β¨
std::is_bounded_array β literally just std::is_bounded_array, that's the whole name, she said what she said π
πΈ Synopsis πΈ
Defined in header <type_traits>:
template< class T > (since C++20)
struct is_bounded_array;
std::is_bounded_array is a UnaryTypeTrait. (yes that's a whole category of trait, she's fancy like that π)
What does she actually do? She checks whether T is an array type of known bound. And she provides the member constant value, which is equal to true if T is an array type of known bound. Otherwise, value is equal to false. periodt.
β οΈ okay important warning bestie: if the program adds specializations forstd::is_bounded_arrayorstd::is_bounded_array_v, the behavior is undefined. like, don't do that. not iconic, don't try it π
π§ Template parameters
Tβ a type to check
π¦ Helper variable template
template< class T >
inline constexpr bool is_bounded_array_v = (since C++20)
is_bounded_array<T>::value;
β Inherited from std::integral_constant
π Member constants
valueβtrueifTis an array type of known bound,falseotherwise β[static](public static member constant)
π Member functions
operator boolβ converts the object tobool, returnsvalue(public member function)operator()β returnsvalueβ (C++14) (public member function)
π Member types
value_typeβbooltypeβstd::integral_constant<bool, value>
π Possible implementation
like, this is roughly the vibe of how she's built under the hood:
template<class T>
struct is_bounded_array : std::false_type {};
template<class T, std::size_t N>
struct is_bounded_array<T[N]> : std::true_type {};
π Notes
Feature-test macro moment!! π΅οΈββοΈ
__cpp_lib_bounded_array_traitsβ value201902Lβ Std(C++20)β Feature:std::is_bounded_array,std::is_unbounded_array
π Example
// Run this code
#include <iostream>
#include <type_traits>
#define OUT(...) std::cout << #__VA_ARGS__ << " : " << __VA_ARGS__ << '\n'
class A {};
int main()
{
std::cout << std::boolalpha;
OUT(std::is_bounded_array_v<A>);
OUT(std::is_bounded_array_v<A[]>);
OUT(std::is_bounded_array_v<A[3]>);
OUT(std::is_bounded_array_v<float>);
OUT(std::is_bounded_array_v<int>);
OUT(std::is_bounded_array_v<int[]>);
OUT(std::is_bounded_array_v<int[3]>);
}
Output:
std::is_bounded_array_v<A> : false
std::is_bounded_array_v<A[]> : false
std::is_bounded_array_v<A[3]> : true
std::is_bounded_array_v<float> : false
std::is_bounded_array_v<int> : false
std::is_bounded_array_v<int[]> : false
std::is_bounded_array_v<int[3]> : true
see how A[3] and int[3] ate and left zero crumbs? π½οΈ known bound = true. the [] girls with no number? false. iconic behavior honestly.
π See also
is_arrayβ checks if a type is an array type β (C++11) (class template)is_unbounded_arrayβ checks if a type is an array type of unknown bound β (C++20) (class template)extentβ obtains the size of an array type along a specified dimension β (C++11) (class template)
okay that's the whole page bestie, you're officially a bounded-array knower now π§ β¨ go forth and static_assert responsibly. mwah π«Ά
source: http://cppreference.com β version 2024.06.10 β std::is_bounded_array(3) π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms