challenge/ is this the longest possible declaration


below is a 2d array hj with 6 keyword/identifiers(6 if you count long twice ) is this the largest possible amount of keywords you can use in one statement? or can you try and create a longer one, obviously the code has to compile it can't just be random keywords thrown together.

1
2

const volatile static unsigned long long hj[2][2] = {{1,2},{3,4}};
constexpr volatile static unsigned long long int hj[2][2] = {{1,2},{3,4}};

long is a shorthand for long int ;)
And I changed const with constexpr because it's longer.
Last edited on
Funny, we've had this question before; http://www.cplusplus.com/forum/lounge/224643/ has some interesting responses.
Last edited on


 
constexpr volatile static decltype(unsigned long long int) hj[2][2] = { { 1ull, 2ull }, { 3ull, 4ull } };


And I think there’s something in the standard that talks about templated constexpr values, so...

 
template <typename T = decltype(unsigned long long int)> constexpr volatile static T hj[2][2] = {{1ull,2ull},{3ull,4ull}};


And then maybe you could initialize the variable with a lambda instead...

 
template <typename T = decltype(unsigned long long int)> constexpr volatile static std::array<std::array<T,2>,2> hj = []() -> constexpr std::array<std::array<T,2>,2> { return { { ((T)1), ((T)2) } , { ((T)3), ((T)4) } } };


But of course you could make the lambda ultra complicated too I guess.. I forget the latest constraints on constexpr functions. so imma leave it.

Just repeat cv qualifiers forever
int const const const ... const const const x;
Or declare an N-level pointer
int *** ... *** px;
Or
inline constexpr auto f = []{ /* arbitrary code */ };

Also
1
2
3
4
int [[whatever]] [[hopefully attributes are acceptable here]] 
[[whoever added attributes in the grammar didnt do a consistent job]]
[[so I am not sure whether or not they are actually acceptable in this position]]
[[although I believe they are intended to be acceptable nearly anywhere]] x; 

Or
char const* forever_decl = R"eos(<insert Tolstoy's War and Peace>)eos";
Last edited on
Hm... Keyword count only.. I’m getting... 17. No repeat would be... 14?

Let’s see pulling from the other thread:
 
template <typename T = decltype(unsigned long long int)> static alignas(0) constexpr const thread_local volatile static std::array<std::array<T,2>,2> hj = []() -> alignas(0) constexpr std::array<std::array<T,2>,2> { return { { ((T)1), ((T)2) } , { ((T)3), ((T)4) } } };
Last edited on
One declarator, no structs, no classes, no lambdas, no compound statements, no cheating:

https://godbolt.org/z/UwUbvP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
template <
  class = decltype(
    void(char{}), char16_t{}, char32_t{}, (short signed int){},
    (unsigned long){}, float{}, (long double){}, 
    (const volatile bool){(true, false)}),
  typename = decltype(
    void(::operator new(alignof(enum std::align_val_t) + sizeof(int)))), 
  typename = decltype(*static_cast<bool*>(nullptr) and_eq (1 and 2 bitand 3),
                      *static_cast<bool*>(nullptr) or_eq  (1 or  2 bitor  3),
                      *static_cast<bool*>(nullptr) xor_eq (1 xor 2),
                      *static_cast<bool*>(nullptr) not_eq (not 1)),
  auto = compl -1u
    ? throw 0
    : dynamic_cast<int>(reinterpret_cast<int>(const_cast<int>(15)))>
alignas(decltype(nullptr)) constexpr inline static int x() noexcept = delete;

/* Keywords missing:
    asm       break      case     catch
    continue  default    do       else
    explicit  extern     for      friend
    goto      if         mutable  namespace
    private   protected  public   static_assert  
    struct    switch     this     thread_local 
    try       typedef    typeid   typename
    union     using      virtual  while
*/


The replaceable allocation functions in <new> are implicitly declared, so I can reference ::operator new and enum std::align_val_t without including any headers.
Last edited on
Daaaammmnnn
I love this.
I spent way too much time on that, LOL
just keeps a continuous build of the statement, updating it every 3 years. XD


Actually looking closely, can’t you stick thread_local in there? What are the constraints on that...?


Edit: no probably not no. Didn’t look close enough lol.
Last edited on
Topic archived. No new replies allowed.