Skip to content

Commit

Permalink
Test field count for huge types
Browse files Browse the repository at this point in the history
  • Loading branch information
runer112 committed Sep 20, 2024
1 parent 5e655d4 commit cbc57cc
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions test/core/run/huge_count.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) 2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <boost/pfr/detail/tuple_size.hpp>

#include <climits>
#include <cstdint>

#if defined(__clang__)
#define ARRAY_MAX (SIZE_MAX >> 3)
#define OBJECT_MAX SIZE_MAX
#elif defined(__GNUC__)
#define ARRAY_MAX INT_MAX
#define OBJECT_MAX SIZE_MAX
#else // defined(_MSC_VER)
#define ARRAY_MAX INT_MAX
#define OBJECT_MAX INT_MAX
#endif

struct A
{
char x[ARRAY_MAX <= (OBJECT_MAX >> 3) ? ARRAY_MAX : OBJECT_MAX >> 3];
};

struct B
{
A a;
A b;
A c;
A d;
A e;
A f;
A g;
A h;
};

struct C
{
A& a;
A b;
A c;
A d;
A e;
A f;
A g;
A h;
};

int main() {
#ifndef _MSC_VER
static_assert(boost::pfr::tuple_size_v<char[ARRAY_MAX]> == ARRAY_MAX, "");
#endif
static_assert(boost::pfr::tuple_size_v<B> == 8, "");
static_assert(boost::pfr::tuple_size_v<C> == 8, "");
}

0 comments on commit cbc57cc

Please sign in to comment.