martinmoene / variant-lite

variant lite - A C++17-like variant, a type-safe union for C++98, C++11 and later in a single-file header-only library
Boost Software License 1.0
239 stars 26 forks source link

Error using large variant in gcc 5.5.0 #15

Closed parkertomatoes closed 6 years ago

parkertomatoes commented 6 years ago

When using a variant with a large number of types under gcc, I get the following error:

.../variant_bug_demo.cpp:2:74: error: wrong number of template arguments (9, should be at least 1)
 nonstd::variant<char,short,int,long,long long,char *,short *,int *,long *> big_variant;
                                                                          ^
In file included from .../variant_bug_demo.cpp:1:0:
.../.conan/data/variant-lite/0.1.0/nonstd-lite/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/variant.hpp:745:7: note:
provided for ‘template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> class nonstd::variants::variant’
 class variant;

CMakeLists.txt:

cmake_minimum_required (VERSION 3.0)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
project(VariantBugDemo 
    LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_library(vbd SHARED variant_bug_demo.cpp)

conanfile.txt:

[requires]
variant-lite/0.1.0@nonstd-lite/stable

[generators]
cmake

variant_bug_demo.cpp:

#include "variant.hpp"
nonstd::variant<char,short,int,long,long long,char *,short *,int *,long *> big_variant;

EDIT: The same code, using \ and std::variant, compiles under gcc 8 with std=c++17

martinmoene commented 6 years ago

variant-lite/0.1.0@nonstd-lite/stable has a maximum of 7 types.

Under C++17, nonstd::variant effectively is std::variant which does not have this limitation (*).

Since 30 July 2018, nonstd::variant has a configurable maximum number of types (default: 16).

There's no release yet that covers this.

(*) I intend to make selecting between nonstd::variant and std::variant configurable as with e.g. nonstd::any.

parkertomatoes commented 6 years ago

That makes sense. Thank you for making these headers, and especially for providing conan packages. It makes it a lot easier to adopt the newer STD classes!