id
stringlengths
16
145
text
stringlengths
1
179k
title
stringclasses
1 value
cpp_utility/0eQsx6ip1DwJpli1_257_0.txt
Delete
cpp_utility/cpp_classes_0_0.txt
##### [ cppreference.com ](/) [ Log in ](/mwiki/index.php?title=Special:UserLogin&returnto=cpp%2Futility%2Fpair "You are encouraged to log in; however, it is not mandatory \[o\]") ##### Namespaces * [ Page ](/w/cpp/utility/pair "View the content page \[c\]") * [ Discussion ](/w/Talk:cpp/utility/pair "Discussio...
cpp_utility/0eQsx6ip1DwJpli1_78_0.txt
Sign in to forward
cpp_utility/constexprarraysize_66_0.txt
#define ARRAY_SIZE(a) type_size( \ type<std::remove_cvref_t<decltype(a)>>)
cpp_utility/constexprarraysize_99_0.txt
Getting to the point where we can access the size of a range as a constant expression - whether that size is part of the type (as it is for C arrays and ` std::array ` ) or a variable part of a ` constexpr ` object (as it would be for a wide variety of ranges) - would require multiple language changes.
cpp_utility/76362_61_0.txt
[ ![@dyumin](https://avatars.githubusercontent.com/u/7953339?s=80&u=0377142aa5372554770ee1881c7b9d199c450429&v=4) ](/dyumin)
cpp_utility/constexprarraysize_55_0.txt
template <typename T> struct type_t { using type = T; }; template <typename T> inline constexpr type_t<T> type{};
cpp_utility/cpp_classes_2_0.txt
##### [ cppreference.com ](/) [ Log in ](/mwiki/index.php?title=Special:UserLogin&returnto=cpp%2Futility%2Ftuple+element "You are encouraged to log in; however, it is not mandatory \[o\]") ##### Namespaces * [ Page ](/w/cpp/utility/tuple_element "View the content page \[c\]") * [ Discussion ](/mwiki/index.php?...
cpp_utility/76362_18_0.txt
* [ The ReadME Project GitHub community articles ](https://github.com/readme)
cpp_utility/0eQsx6ip1DwJpli1_181_0.txt
![Daryle Walker's profile photo](//lh3.googleusercontent.com/a-/ALV- UjXoim9G9QIWcI07jqQyhXOw1okhhNDGrBeQvqH0u7z0C0ppkys=s40-c)
cpp_utility/constexprarraysize_110_0.txt
[ c++ ](/tags/c/) [ c++20 ](/tags/c-20/) [ ranges ](/tags/ranges/) [ optional ](/tags/optional/) [ concepts ](/tags/concepts/) [ c++17 ](/tags/c-17/) [ spaceship ](/tags/spaceship/) [ c++23 ](/tags/c-23/) [ span ](/tags/span/) [ d ](/tags/d/)
cpp_utility/0eQsx6ip1DwJpli1_236_0.txt
Copy link
cpp_utility/76362_34_0.txt
Query
cpp_utility/CanIconstexpranstdar_34_0.txt
Profile photo for Fr Fr Nov 28 Related Why can't std::map be constexpr? It can.
cpp_utility/cpp_tag_2_1.txt
parison "cpp/utility") [ three_way_comparable three_way_comparable_with ](/w/cpp/utility/compare/three_way_comparable "cpp/utility/compare/three way comparable") (C++20) (C++20) [ strong_ordering ](/w/cpp/utility/compare/strong_ordering "cpp/utility/compare/strong ordering") (C++20) [ weak_ordering ](/w/cpp/u...
cpp_utility/0eQsx6ip1DwJpli1_109_0.txt
David Krauss < [ pot...@gmail.com ]() > writes:
cpp_utility/76362_3_0.txt
[ ](https://github.com/)
cpp_utility/constexprarraysize_45_0.txt
std::vector<int> v5 = {1, 2, 3, 4, 5}; f(std::span<int, 5>(v5)); // well-formed
cpp_utility/0eQsx6ip1DwJpli1_139_0.txt
### Gabriel Dos Reis
cpp_utility/CanIconstexpranstdar_48_0.txt
You can take control of HTML5, CSS3, and JavaScript in a completely visual canvas — and let Webflow translate your design into clean, semantic code that’s ready to publish to the web, or hand off
cpp_utility/0eQsx6ip1DwJpli1_0_0.txt
[ ![](https://fonts.gstatic.com/s/i/productlogos/groups/v9/web-48dp/logo_groups_color_1x_web_48dp.png) Groups ](./my-groups "Groups")
cpp_utility/0eQsx6ip1DwJpli1_123_0.txt
Sign in to forward
cpp_utility/76362_122_0.txt
[ ![@shafik](https://avatars.githubusercontent.com/u/6431709?s=52&v=4) ](/shafik) [ ![@dyumin](https://avatars.githubusercontent.com/u/7953339?s=52&v=4) ](/dyumin) [ ![@EugeneZelenko](https://avatars.githubusercontent.com/u/9355329?s=52&v=4) ](/EugeneZelenko)
cpp_utility/0eQsx6ip1DwJpli1_284_0.txt
Show original message
cpp_utility/constexprarraysize_79_0.txt
constexpr std::array<int, 5> some_const_array = {1, 2, 3, 4, 5}; constexpr std::span<int> dynamic_span = some_const_array; // ok static_assert(dynamic_span.size() == 5); // ok
cpp_utility/constexprarraysize_18_0.txt
template <typename T, size_t N> constexpr size_t array_size(T (&)[N]) { return N; }
cpp_utility/76362_19_0.txt
Repositories
cpp_utility/cpp_classes_4_1.txt
nt ](/w/cpp/utility/breakpoint "cpp/utility/breakpoint") (C++26) [ Three-way comparison ](/w/cpp/utility#Three-way_comparison "cpp/utility") [ three_way_comparable three_way_comparable_with ](/w/cpp/utility/compare/three_way_comparable "cpp/utility/compare/three way comparable") (C++20) (C++20) [ strong_orderi...
cpp_utility/0eQsx6ip1DwJpli1_285_0.txt
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
cpp_utility/cpp_classes_1_0.txt
##### [ cppreference.com ](/) [ Log in ](/mwiki/index.php?title=Special:UserLogin&returnto=cpp%2Futility%2Ftuple+size "You are encouraged to log in; however, it is not mandatory \[o\]") ##### Namespaces * [ Page ](/w/cpp/utility/tuple_size "View the content page \[c\]") * [ Discussion ](/mwiki/index.php?title=...
cpp_utility/76362_57_0.txt
[ dyumin ](/dyumin) opened this issue Dec 25, 2023 · 3 comments
cpp_utility/constexprarraysize_85_0.txt
std::vector<std::span<int, 5>> bunch_of_spans; bunch_of_spans.push_back(c_array); bunch_of_spans.push_back(cpp_array); bunch_of_spans.push_back(dynamic_span);
cpp_utility/0eQsx6ip1DwJpli1_171_0.txt
Show original message
cpp_utility/cpp_tag_1_0.txt
##### [ cppreference.com ](/) [ Log in ](/mwiki/index.php?title=Special:UserLogin&returnto=cpp%2Futility%2Fin+place "You are encouraged to log in; however, it is not mandatory \[o\]") ##### Namespaces * [ Page ](/w/cpp/utility/in_place "View the content page \[c\]") * [ Discussion ](/mwiki/index.php?title=Talk...
cpp_utility/0eQsx6ip1DwJpli1_175_0.txt
> On 10/13/13 4:55 PM, Gabriel Dos Reis wrote: > >
cpp_utility/constexprarraysize_97_0.txt
### Recap __
cpp_utility/0eQsx6ip1DwJpli1_124_0.txt
Delete
cpp_utility/constexprarraysize_62_0.txt
// this is fine, s.size() is a constant expression static_assert(s.size() == 5);
cpp_utility/76362_120_0.txt
No branches or pull requests
cpp_utility/constexprarraysize_101_0.txt
__ [ c++ ](/tags/c/) [ constexpr ](/tags/constexpr/) [ span ](/tags/span/)
cpp_utility/0eQsx6ip1DwJpli1_215_0.txt
to std-dis...@isocpp.org, thomas....@gmail.com
cpp_utility/constexprarraysize_19_0.txt
This beats the C macro approach both by not being a macro and by not giving bogus answers for ` vector<T> ` . But it has possibly-surprising limitations:
cpp_utility/76362_102_0.txt
Copy link
cpp_utility/CanIconstexpranstdar_44_0.txt
If your array is owned by an std::unique_ptr then the std::unique_ptr has ownership, and you should not be using another smart pointer to provide access to the object.
cpp_utility/0eQsx6ip1DwJpli1_147_0.txt
You do not have permission to delete messages in this group
cpp_utility/0eQsx6ip1DwJpli1_170_0.txt
Sign in to report message
cpp_utility/0eQsx6ip1DwJpli1_67_0.txt
Unfortunately, during the Chicago meeting it was decided that a conforming implementation is no longer permitted to add constexpr to other functions, see
cpp_utility/CanIconstexpranstdar_11_0.txt
Profile photo for Kurt Guntheroth Kurt Guntheroth Software Engineer and WriterUpvoted by Alan Mellor , Started programming 8 bit computers in 1981Author has 19.3K answers and 238.4M answer views · 4y Related Why can't std::map be constexpr? std::map cannot be constexpr because the compiler cannot evaluate std::map memb...
cpp_utility/0eQsx6ip1DwJpli1_265_0.txt
Le samedi 12 octobre 2013 17:05:21 UTC+2, Daniel Krügler a écrit :
cpp_utility/76362_69_0.txt
int main() { return Array[3]; }
cpp_utility/0eQsx6ip1DwJpli1_188_0.txt
Sign in to forward
cpp_utility/constexprarraysize_35_0.txt
C++20 will have a new type ` std::span ` ( [ cppref ](https://en.cppreference.com/w/cpp/container/span) , I’ve written about ` span ` before [ here ](/c++/2018/12/03/span-best-span/) ), which is a contiguous view on ` T ` . ` span ` comes in two flavors: dynamic extent and fixed extent. Roughly speaking:
cpp_utility/constexprarraysize_78_0.txt
Would this even be a sufficient rule? Still no! It still wouldn’t work for the example I showed earlier:
cpp_utility/CanIconstexpranstdar_28_0.txt
Sponsored by JetBrains Write better C++ code with less effort. Boost your efficiency with refactorings, code analysis, unit test support, and an integrated debugger. Profile photo for Joe Zbiciak Joe Zbiciak I have been programming since grade schoolUpvoted by Matt Godbolt , 20+ years' professional programming experien...
cpp_utility/0eQsx6ip1DwJpli1_245_0.txt
> > > > > N3691 is supposed to be identical to N3690, other than the cover sheet. If > it's not, that's unintended, and you should let the project editor know. > (N3690 is the Committee Draft, N3691 is the Working Draft). In this > instance, I don't see what you're referring to: in both documents, page 764 > contains a...
cpp_utility/0eQsx6ip1DwJpli1_46_0.txt
return compile_time_sort_imp ( seq , idx ); }
cpp_utility/constexprarraysize_36_0.txt
// fixed-extent: always has size Extent, only needs // to store a single pointer template <typename T, size_t Extent = dynamic_extent> struct span { T* ptr;
cpp_utility/0eQsx6ip1DwJpli1_154_0.txt
David Krauss < [ pot...@gmail.com ]() > writes:
cpp_utility/constexprarraysize_63_0.txt
// ... but this still wouldn't work! std::span<int, 5> fixed = s;
cpp_utility/0eQsx6ip1DwJpli1_114_0.txt
A decade later, the world looks very different; it is hard to live with history, but that is the price we pay for progress.
cpp_utility/cpp_tag_2_0.txt
##### [ cppreference.com ](/) [ Log in ](/mwiki/index.php?title=Special:UserLogin&returnto=cpp%2Futility%2Fnontype "You are encouraged to log in; however, it is not mandatory \[o\]") ##### Namespaces * [ Page ](/w/cpp/utility/nontype "View the content page \[c\]") * [ Discussion ](/mwiki/index.php?title=Talk:c...
cpp_utility/0eQsx6ip1DwJpli1_160_0.txt
unread,
cpp_utility/0eQsx6ip1DwJpli1_263_0.txt
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
cpp_utility/0eQsx6ip1DwJpli1_41_0.txt
constepxr std :: array < int , 4 > sorted_indices = compile_time_sort < 4 , 6 , 1 , 9 >(); // don't compile
cpp_utility/cpp_classes_0_3.txt
---|---|--- ### [ [ edit ](/mwiki/index.php?title=cpp/utility/pair&action=edit&section=2 "Edit section: Member types") ] Member types Member type | Definition ---|--- ` first_type ` | ` T1 ` ` second_type ` | ` T2 ` ### [ [ edit ](/mwiki/index.php?title=cpp/utility/pair&action=edit&section=3 "E...
cpp_utility/76362_85_0.txt
[ https://godbolt.org/z/M5YG1739x ](https://godbolt.org/z/M5YG1739x)
cpp_utility/0eQsx6ip1DwJpli1_71_0.txt
![David Krauss's profile photo](//lh3.googleusercontent.com/a-/ALV- UjV2RLbClvucFZRduliIAc5z0LW8kUMSBrNMCjw_V88t7JhBW6k=s40-c)
cpp_utility/76362_29_0.txt
Include my email address so I can be contacted
cpp_utility/0eQsx6ip1DwJpli1_76_0.txt
Sign in to reply to author
cpp_utility/0eQsx6ip1DwJpli1_83_0.txt
Sign in to report message
cpp_utility/constexprarraysize_89_0.txt
That is, the conversion to ` span ` happens on the way into the function. For ` dynamic_span ` , it’s still a constant expression here - so either we can still treat it as a constant expression for constraint purposes (as with the function parameter constraints approach in P1733) or we can add an overloaded constructo...
cpp_utility/constexprarraysize_47_0.txt
void f(std::span<int, 5>);
cpp_utility/0eQsx6ip1DwJpli1_37_0.txt
int main () { constexpr int i1 = foo (); constexpr int i2 = bar (); //constepxr int i3 = baz(); // don't compile }
cpp_utility/CanIconstexpranstdar_46_0.txt
There’s v
cpp_utility/0eQsx6ip1DwJpli1_220_0.txt
>> Hello, > I'm playing around with the relaxed constraints on constexpr functions with > clang + libc++ trunk and noticed something strange with std::array : Because > std::array lacks a constexpr "reference operator[]" (23.3.2.1.3), it is > impossible to instantiate an std::array in a constepxr function and write in...
cpp_utility/constexprarraysize_54_0.txt
In the case I’m describing here, the size is encoded in the type. So if we change the way we query the size to query based on the type of the object instead of the value of the object, we can side-step these problems:
cpp_utility/0eQsx6ip1DwJpli1_81_0.txt
Copy link
cpp_utility/CanIconstexpranstdar_25_0.txt
Of course you cannot make it to be a constexpr. I believe the error message already gave you some hints. Simply, a constexpr variable is not a runtime variable and it is reduced just to its value at compile time. Hence to make compiler work manageable constexpr is required to be of literal type : C++ named requirements...
cpp_utility/constexprarraysize_16_0.txt
Macro notwithstanding, this works fine in all contexts. In C++, it unfortunately also compiles for any types with overloaded ` operator[] ` and gives a nonsense result. Can we provide a type-safe way to do better?
cpp_utility/CanIconstexpranstdar_23_0.txt
When you instantiate a std::array, you have to provide an element type and the total array size in elements. Both the element type and size become part of the type for the newly-instantiated std::array. These details
cpp_utility/76362_84_0.txt
consteval function works fine (constexpr function is not though)
cpp_utility/constexprarraysize_21_0.txt
All compilers reject ` s1 ` (gcc still accepted it when I started writing this post, but [ that bug ](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66477) has been fixed. That’s some timing!)
cpp_utility/0eQsx6ip1DwJpli1_262_0.txt
Show original message
cpp_utility/0eQsx6ip1DwJpli1_273_0.txt
unread,
cpp_utility/cpp_tag_1_1.txt
lity/breakpoint "cpp/utility/breakpoint") (C++26) [ Three-way comparison ](/w/cpp/utility#Three-way_comparison "cpp/utility") [ three_way_comparable three_way_comparable_with ](/w/cpp/utility/compare/three_way_comparable "cpp/utility/compare/three way comparable") (C++20) (C++20) [ strong_ordering ](/w/cpp/uti...
cpp_utility/0eQsx6ip1DwJpli1_290_0.txt
I just want to say again that with the current draft we can use and modify plain C-array in constexpr function but not std::array, it should be a defect, no ?
cpp_utility/CanIconstexpranstdar_9_0.txt
constexpr int f(int const *p) { return *p; } int main() { constexpr int x = 42; constexpr int y = f(&x); // Okay. constexpr int const *p = &x; // Error. int const *q = &x; // Okay. } Note how the address of the local variable x can be used to compute a consta
cpp_utility/constexprarraysize_108_0.txt
](/c++/2020/03/30/span-comparisons/)
cpp_utility/constexprarraysize_98_0.txt
Basically, the best way to get the size of an array to be used as a constant expression is still to use a macro - in C++, we can make that macro more type safe than the initial C version, but still a macro.
cpp_utility/0eQsx6ip1DwJpli1_186_0.txt
Sign in to reply to author
cpp_utility/0eQsx6ip1DwJpli1_271_0.txt
![thomas....@gmail.com's profile photo](//lh3.googleusercontent.com/a-/ALV- UjVq8xDenE_ld09oVulVi_L6DDR0P6HNO238KE-HE-hEJwaYWd5iOQ=s40-c)
cpp_utility/0eQsx6ip1DwJpli1_250_0.txt
### thomas....@gmail.com
cpp_utility/constexprarraysize_64_0.txt
` s ` ’s size is a constant expression, but it’s not tied to its type - these type- based approaches wouldn’t work.
cpp_utility/0eQsx6ip1DwJpli1_194_0.txt
Show original message
cpp_utility/0eQsx6ip1DwJpli1_7_0.txt
[ Sign in ](https://accounts.google.com/ServiceLogin?hl=en&passive=true&continue=https://groups.google.com&ec=GAZA0AM)
cpp_utility/76362_33_0.txt
Name
cpp_utility/0eQsx6ip1DwJpli1_184_0.txt
Oct 14, 2013, 3:06:27 PM 10/14/13
cpp_utility/constexprarraysize_34_0.txt
Before getting into more detail about the problem itself, let’s take a look at why this matters. The following is just one motivating example. I picked it because it’s probably the easiest to look at, but just keep in mind that this is far from the only reason we might care about this sort of thing.
cpp_utility/CanIconstexpranstdar_22_0.txt
For example, I can pass around an arbitrary data structure in C++ by simply taking its address and casting to void *. I can pass the resulting pointer quite efficiently to a function that accepts a void *; however, that function is quite limited in what it can do with that pointer.
cpp_utility/CanIconstexpranstdar_10_0.txt
Related questions Why can't std::map be constexpr? How do I use the C++20 constexpr std::vector? Is std::vector faster than std::array? Why is there std::array<> in C++11? What are the benefits of it? When should one use std::array instead std::vector? What does std::array offer that std::vector lacks? Profile photo fo...