Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [variant-type]

A data type or a class designed to emulate a data type that holds a single value of a type that is either from an explicitly (compile-time) specified list, or arbitrary. The actual type of the stored value is only known at runtime.

0
votes
0answers
70 views

Algebraic data types in C++ [on hold]

After some exposure to Haskell I came to love ADTs to describe 'is one of' and tree-like structures. But now that I work with C++ a lot more I want to use them in C++ too. As far as I know I have two ...
0
votes
1answer
31 views

Swift append an array when it's been declared as Any

I'm learning Swift and I have a following problem: I create a dictionary containing some data, one of which is stored as an array. I want make an operation on this array to add some info. Currently I ...
2
votes
0answers
45 views

Creating an array of distinct objects with an identical method that can be evaluated (mapped) at compile-time (constexpr)

In a ray tracing project that I'm trying to make compile-time (constexpr) for fun and challenge, I've run into a bit of an issue: I have an object (intersection) that needs to refer to one of a group ...
0
votes
1answer
110 views

create sorted vector of content of two binary search trees in sorted order

You are given two binary search trees, the goal is produce a sorted array of elements containing elements from both the trees. I wanted to know if there is a simpler approach, and if the use of ...
3
votes
1answer
156 views

Template Metaprogramming Discriminated Union

std::variant and boost::variant do not require the types involved to be unique, but lose some functionality when types repeat. ...
2
votes
1answer
345 views

Variant implementation in C++

I've been fiddling with templates and compile time stuff i implemented a variant container and wanted some opinions and recommendations this is just a learning exercise, a couple template classes not ...
5
votes
0answers
172 views

Value semantic type eraser

I've been using std::unique_ptr for cases where I want to store a derived-type value with type erasure, and felt that unique_ptr being nullable was an undesirable ...
11
votes
1answer
983 views

Simple C++ alternative to exceptions for embedded systems

I have researched ways to implement a simpler alternative for C++ exceptions. The problem I had with exceptions was the complex and not-portable stack unwinding process which makes it hard to ...
2
votes
0answers
449 views

Custom basic std::variant

I was amazed by std::variant and got inspired to write my own. For now, it supports constructor+destructor pair, assignment operator and ...
3
votes
0answers
347 views

C++ variant and variant subsets

I seem to be in a love-hate relationship with C++. It can make some parts of your code elegant and easy to grasp, and some others become an inconceivable mess. And it's not the language itself causing ...
14
votes
1answer
264 views

An implementation of a static any type

This describes type util::any<std::size_t size, std::size_t align> - an implementation of std::any with a static size/no ...
10
votes
1answer
459 views

Variant class using generic programming

My goal is to learn a bit more about generic programming in C++. So, one of the trickiest things I've heard you can do is creating a Variant class. This took me a while and I needed to read and study ...
2
votes
0answers
79 views

Any class implementation - follow-up

Based on the previous question, I have improved it to make it insert regular function. Also, I have implemented a new template approach to obtain the signature from any function by testing its ...
4
votes
1answer
1k views

Runtime compiler for getting/setting runtime property values

I've been playing about with runtime compilation to allow me to get/set runtime property values in C#, and so far I have come up with a class. This allows me to write code like the following which ...
4
votes
0answers
251 views

Any class implementation

I was inspired from question here, to implement function container that holder any kind of function by using boost::any, I have carried on and extend it further to make the functions holder accept ...
3
votes
0answers
155 views

Trivial full-fledged variant for constexpr (proof of concept)

I want to show you how to implement variant like boost::variant, but almost for constexpr, ...
7
votes
3answers
422 views

Type-agnostic BubbleSort in C

I'm trying out different sorting algorithms for learning purposes, here I'm doing a "type-agnostic" bubbleaort. I modeled the function signature after the standard library's ...
2
votes
1answer
382 views
6
votes
1answer
4k views

Storing collections of objects of any type

I've put together a class whose goal is to store objects of arbitrary type, with each type having its own vector for contiguity. I'd like to gather advice on what I have so far before I carry on. Let ...
10
votes
1answer
1k views

union based approach to implement variant

This implementation of discriminated union based on C++ inherent unions and inspired by this and this articles. ...
3
votes
0answers
162 views

any that can hold arrays

I've tried to make a better any than before: ...
11
votes
2answers
3k views

Multiple dispatch with variant and multi visitation in C++

The following program is a demonstration of variant and double visitation used to obtain double dispatch between the elements of two inhomogeneous containers. Most of the work is done at compile time. ...
15
votes
2answers
5k views

Variant class with full move support

I tried to write my own variant class, that is fully move-semantics enabled. WRT to implemented visitors, they don't require any policy and like to be derived from <...
28
votes
1answer
3k views

Yet another 'any' class implementation, named 'some'

This is a follow-up of 'any' class implementation. After posting my answer, I kept working on the code towards parameterizing with respect to memory management as I had promised. I ended up in some ...
11
votes
1answer
1k views

Clone of Boost Variant

As part of learning C++, with special emphasis on C++11, I wanted to implement the equivalent of Boost's Variant (located here). My code is available at variant.hpp, with the current version given ...
25
votes
2answers
9k views

C++11 Any class

This is a polymorphic wrapper capable of holding any type. (It is loosely based on boost::any) In particular, this is useful when you want to store a ...
16
votes
2answers
2k views

boost::any replacement with std::unique_ptr support

I needed a boost.any look-a-like, that could handle a std::unique_ptr. I came up with this. Please provide some C++11 criticism. ...