Eggs.Variant is a C++11/14/17 generic, type-safe, discriminated union.

Overview

Eggs.Variant

Introduction

Eggs.Variant is a C++11/14/17 generic, type-safe, discriminated union. See the documentation at http://eggs-cpp.github.io/variant/.

Requirements

The library requires a standard conformant implementation of C++11; a few additional features are only available under C++14/17. Some effort was done to support incomplete language or standard library implementations —see Config —. There are no external dependencies.

The library is continuously tested with the following configurations: Build Status Build Status

  • Clang 3.9, 4, 5
  • GCC 5, 6, 7
  • Apple LLVM 7.3, 8.3, 9.1
  • MSVC 2015, 2017

[Note: Older versions of Clang (3.0+) and GCC (4.6+) are no longer tested, but should still work; please report any issues if you are using them. Older versions of MSVC are not supported.]


Copyright Agustín Bergé, Fusion Fenix 2014-2018

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

Issues
  • Compiling error VS 2015 Update 3

    Compiling error VS 2015 Update 3

    Hi,

    I'm using Visual Studio 2015 Update 3 and I'm getting this error. I use the commit 91dae8040425e51aab24d25788336063e1c6837e

    image

    Commenting this line (28) make the compilation succeed.

    opened by erakis 13
  • in_place signatures seems wrong

    in_place signatures seems wrong

    The signatures of this class and functions seems wrong.

    struct in_place_t {};
    template <std::size_t I>
    in_place_t in_place(unspecified<I>);
    template <class T>
    in_place_t in_place(unspecified<T>);
    

    There is a parameter to in_place, but elsewhere there is no argument passed.

    How in_place_t can remember the Ior the T?

    BTW, where in_place_tis used?

    opened by viboes 12
  • support for recursive_wrapper

    support for recursive_wrapper

    Do you plan to introduce the support for recursive_wrapper like boost::variant have? I know, that common wrapping of incomplete types breaks type traits on whole variant type, but imposing constraints on using such variant types makes they still useful.

    opened by tomilov 11
  • CMake build fails with unsupported language features.

    CMake build fails with unsupported language features.

    f9bcaf334bd4e0ddb7bac26fbaf3cd054be975a5 fails with unsupported language features errors like:

    ../include/eggs/variant/detail/pack.hpp:22:9: error: unknown type name 'constexpr'
            EGGS_CXX11_CONSTEXPR bool operator==(empty) const { return true; }
    

    requiring C++14 fixes this but I'm not sure if that's the best way to go. (PR coming).

    opened by jbcoe 8
  • Create debugger visualiser for eggs::variant

    Create debugger visualiser for eggs::variant

    eggs::variant is proving invaluable to me but is hard to interpret in a debugger.

    It would be useful to provide debugger visualisers such as those for Visual Studio:

    https://blogs.msdn.microsoft.com/vcblog/2015/09/28/debug-visualizers-in-visual-c-2015/

    or LLDB:

    http://lldb.llvm.org/varformats.html

    Thanks for your great work on this library.

    opened by jbcoe 7
  • Implement get_if overloads (was: No compile error with invalid call to target)

    Implement get_if overloads (was: No compile error with invalid call to target)

    Hello:

    The compiler happily accepts the following code:

    #include <eggs/variant.hpp>
    #include <string>
    int main()
    {
      eggs::variant<int, bool> foo;
      foo.target<std::string>();
    }
    

    couldn't it be made so that target<T> only compiles if the variant actually has a T type ?

    opened by jcelerier 6
  • Internal compiler error

    Internal compiler error

    I'll try to compile eggs::variant with gcc 7.3.1 (devtoolset-7) on linux and got folowing error:

    In file included from <...>/variant/include/eggs/variant.hpp:13:0,
                              from <...>/variant/test/swap.cpp:8:
    <...>/variant/include/eggs/variant/variant.hpp: In substitution of ‘template<class U, class NoCopy, class NoTag, long unsigned int I, class T, typename std::enable_if<(std::is_constructible<T, U>::value && (! std::is_convertible<U, T>::value)), bool>::type <anonymous> > constexpr eggs::variants::variant<int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::variant(U&&) [with U = int; NoCopy = void; NoTag = void; long unsigned int I = <missing>; T = <missing>; typename std::enable_if<(std::is_constructible<T, U>::value && (! std::is_convertible<U, T>::value)), bool>::type <anonymous> = <missing>]’:
    <...>/variant/test/swap.cpp:116:46:   required from here
    <...>/variant/include/eggs/variant/variant.hpp:696:13: internal compiler error: unexpected expression ‘I’ of kind template_parm_index
               , typename T = typename detail::at_index<
                 ^~~~~~~~
    
    Please submit a full bug report,
    with preprocessed source if appropriate.
    See <http://bugzilla.redhat.com/bugzilla> for instructions.
    Preprocessed source stored into /tmp/ccYpdTC0.out file, please attach this to your bugreport.**
    

    With gcc 6 it compiles and works fine.

    machine: centos-release-7-5.1804.el7.centos.2.x86_64 kernel: Linux 3.10.0-862.9.1.el7.x86_64

    gcc --version: gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)

    opened by yuriv 5
  • Dispatching triviality of copy/move-construction/assignment all together

    Dispatching triviality of copy/move-construction/assignment all together

    All mentioned operations, expressed by corresponding special functions, are all the same by its nature. Say, both copy-construction/assignment and move-construction/assignment is just a copy (in both cases!) of memory from one (source, right hand side) properly aligned and sized storage to another (destination, left hand side) (possibly uninitialized). There is not any difference between all of them. The (imaginary) difference arised when considered some artificial class with forced assymetry in mentioned special functions (i.e. some of them are user-provided or explicitly deleted, but others are defaulted). But such a class can be considered as oxymoron, because having (any) one of copy/move-constructor/assignment operator one can emulate each other absolutely legally by using this single existing special function to copy source memory to destination (or simply using std::memcpy). Hence, it make sense to only consider types with all trivial mentioned special functions or with not trivial of all of them.

    I think it means, that (in real life) there is no need to dispatch triviality of all the possible combinations for all four (or even eight, if we consider const && and & along with const & and &&) special functions. If any one of them is not trivial, then all others should be treated as not trivial too (but (instead) maybe converse is right if triviality has logical priority).

    What do you think about this?

    opened by tomilov 5
  • Heterogenous multi-visitation ?

    Heterogenous multi-visitation ?

    Hello,

    Is there a way to make multi-visitation with apply() & multiple variant types ?

    e.g.

    eggs::variant<int, float> v1;
    eggs::variant<foo, bar> v2;
    
    struct vis { 
        void operator()(int, foo);
        void operator()(int, bar);
        void operator()(float, foo);
        void operator()(float, bar);
    };
    
    eggs::variants::apply(vis{}, v1, v2);
    

    thanks !

    opened by jcelerier 5
  • Missing else part on constexpr variant(variant const& rhs); effects

    Missing else part on constexpr variant(variant const& rhs); effects

    In

    constexpr variant(variant const& rhs);
    
        Requires: std::is_copy_constructible_v<T> is true for all T in Ts....
        Effects: If rhs has an active member of type T, initializes the active member as if direct-non-list-initializing an object of type T with the expression *rhs.target<T>().
    

    you need to add how the constructor behaves is rhshas no active member.

    opened by viboes 5
  • Mitigating combinatorial explosion when only a few types in the variant benefit from movability

    Mitigating combinatorial explosion when only a few types in the variant benefit from movability

    Hello,

    I have this variant in my code :

    eggs::variant<int, bool, float, char, std::string, std::vector<foo>> 
    

    and a few other trivial types.

    Now when I write visitors, I try to do them in a "as-generic-as-possible" way :

    struct my_visitor
    { 
       template<typename T, typename U>
       auto operator(T&& t, U&& u) 
       { return generic_operation(t, u); }
    
       template<typename U>
       auto operator(const std::string& s, U&& u) 
       { return string_specific_operation(s, u); }
    
       template<typename U>
       auto operator(std::string&& s, U&& u) 
       { return string_specific_operation(std::move(s), u); }
    };
    

    My problem is : how could I generically write my visitor to match the "trivial" types (let's say matchin std::is_numeric) in my variant so that they are always taken by value, without having to specialize either for all trivial types or for all non trivial types ? Because else I have twice the number of functions generated, and passing int by either const & or && instead of just int does not gain anything.

    opened by jcelerier 4
Easy to use, header only, macro generated, generic and type-safe Data Structures in C

C Macro Collections Easy to use, header only, macro generated, generic and type-safe Data Structures in C. Table of Contents Installation Contributing

Leonardo Vencovsky 311 Aug 2, 2022
Library of generic and type safe containers in pure C language (C99 or C11) for a wide collection of container (comparable to the C++ STL).

M*LIB: Generic type-safe Container Library for C language Overview M*LIB (M star lib) is a C library enabling to use generic and type safe container i

PpHd 505 Aug 7, 2022
Functional, Type safe, Lazy abstractions for generic iterators in C

C-Iterplus Functional abstractions for working with iterators, as demonstrated in c-iterators. Finding the longest common prefix of an array of string

Chase 26 Jul 25, 2022
Cross-platform STL-styled and STL-compatible library with implementing containers, ranges, iterators, type traits and other tools; actors system; type-safe config interface.

Yato A small repository where I'm gatherting useful snippets and abstractions for C++ development. Yato includes 3 main modules: multidimensional cont

Alexey 9 Jul 22, 2022
A realtime/embedded-friendly C++11 variant type which is never empty and prevents undesirable implicit conversions

strict variant Do you use boost::variant or one of the many open-source C++11 implementations of a "tagged union" or variant type in your C++ projects

Chris Beck 91 Jul 14, 2022
A library of type safe sets over fixed size collections of types or values, including methods for accessing, modifying, visiting and iterating over those.

cpp_enum_set A library of type safe sets over fixed size collections of types or values, including methods for accessing, modifying, visiting and iter

Carl Dehlin 22 Jun 16, 2022
Strong typedef - A class template that creates a new type that is distinct from the underlying type, but convertible to and from it

jss::strong_typedef <Tag, ValueType, Properties...> This is an implementation of a C++17 class template that provides a wrapper type that is convertib

Anthony Williams 100 Jul 19, 2022
Finite State Machine implementation using std::variant

mp::fsm Implementation of Finite State Machine presented by me on CppCon 2018 in a talk Effective replacement of dynamic polymorphism with std::varian

Mateusz Pusz 63 Aug 3, 2022
A C++20 implementation of safe (wrap around) integers following MISRA C++ rules

PSsimplesafeint A C++20 implementation of safe (wrap around) integers following MISRA C++ rules. I might also work on a C++17 implementation, but this

Peter Sommerlad 34 Jul 28, 2022
libsrt is a C library for writing fast and safe C code, faster.

libsrt is a C library for writing fast and safe C code, faster. It provides string, vector, bit set, set, map, hash set, and hash map handling. Suitable for soft and hard real-time. Allows both heap and stack allocation. *BETA* (API still can change: suggestions are welcome)

null 511 Aug 1, 2022
A library of generic data structures.

Collections-C A library of generic data structures including a list, array, hashtable, deque etc.. Examples Building and Installing Using the library

Srđan Panić 2.4k Aug 7, 2022
A collecton of generic reference counted data structures, tools to create compatible C style classes, and demo applications

The Offbrand library is a collection of reference counted generic data structures written in C for C. The library includes bash scripts to assist in t

Tyler Heck 82 Mar 4, 2022
Generic parse tree, configurable lexer, `lemon` parser generator, wrapped for C++17 and Python 3.

This project augments the Lemon parser generator with a high-level parse tree interface, grammar action DSL, and an integrated, configurable lexer allowing the creation of an entire standalone, object-oriented parser from a single input grammar file. The entire parser is written in native C/C++, and the parser interface is made comfortably available to both C++ and Python3 applications.

Aubrey R. Jones 11 Jun 16, 2022
Generic Data Structures In C

Generic Data Structures In C Objective: ability to use data structures with full functionality on any data type type safety is absolutely critical, ma

null 5 May 4, 2022
Typesafe, Generic & Fastest Set Data structure implementation in C

Typesafe & Fast as fuck Set in C Key Features Extremely fast non-cryptographic hash algorithm XXHash Complete Typesafe APIs Double Hashing to avoid bo

Robus Gauli 4 Sep 6, 2021
Typesafe, Generic & Extremely fast Dictionary in C 🚀

CDict.h Typesafe, Generic, and Extremely Fast Dictionary in C ?? Key Features Extremely fast non-cryptographic hash algorithm XXHash Complete Typesafe

Robus Gauli 14 May 20, 2022
Well Factored, Non-Recursive, General & Generic BSTs in ANSI C

This one set of files implements well factored/layered binary search trees (BSTs) with 5 balancing schemes (none, avl, red-black, L(k), and splay) and

null 2 Dec 7, 2021
Generic single-file implementations of AVL tree in C and C++ suitable for deeply embedded systems

Cavl Generic single-file implementation of AVL tree suitable for deeply embedded systems. Simply copy cavl.h or cavl.hpp (depending on which language

Pavel Kirienko 5 Apr 14, 2022
A generic raft library inspired etcd in C++

Overview Raft is a protocol with which a cluster of nodes can maintain a replicated state machine. The state machine is kept in sync through the use o

ERaftGroup 147 Aug 10, 2022