Sujet : Re: Array size validity and SFINAE
De : chris.m.thomasson.1 (at) *nospam* gmail.com (Chris M. Thomasson)
Groupes : comp.lang.c++Date : 02. Mar 2026, 01:36:01
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <10o2m1i$n2lg$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla Thunderbird
On 3/1/2026 8:23 AM, Andrey Tarasevich wrote:
On Sun 3/1/2026 7:55 AM, Marcel Mueller wrote:
#include <iostream>
>
struct S { static constexpr int N = -1; };
>
template <typename T> void foo(int [T::N])
{
std::cout << "array" << std::endl;
}
>
template <typename T> void foo(...)
{
std::cout << "..." << std::endl;
}
>
int main()
{
foo<int>(0);
}
>
GCC outputs "array", Clang and MSVC output "..."
>
You are taking an array by value.
There's no such thing as "taking an array by value". Neither in C nor in C++.
pseudo-code sorry for any typos... Not your main point, but
struct foo
{
int xxx[10];
};
void
bar(struct foo bar)
{
bar.xxx[0] = 123;
}
This might not be the intention and might take a slice.
???
Since the array index is unsigned -1 is UB or in fact expand to UINT_MAX.
Um... My question is intended for people who have "language lawyer" level of understanding the language. You are obviously not quite there yet.
At some point in the future you you might come across the concept colloquially known as SFINAE (which is mentioned in the subject of my question). Once you learn what it is (if ever), you will understand what this question is about.
Haut de la page
Les messages affichés proviennent d'usenet.
NewsPortal