stdany Questions

5

Solved

I recently came across the std::any class, introduced in C++17, based on boost::any. This class can "hold an instance of any type" and auto automatically deduces the data type of a variab...
Niece asked 19/10, 2020 at 16:18

8

Solved

Basically I want MyClass that holds a Hashmap that maps Field name(string) to ANY type of Value.. For this purpose I wrote a separate MyField class that holds the type & value information.. T...
Foti asked 11/7, 2014 at 16:18

1

Solved

There's a value stored in std::any and I want to know if it's an integral value (char, short, int, long, both signed and unsigned) or a floating point value (float, double), or something else. If I...
Militate asked 25/4, 2021 at 12:27

5

I want to check whether an element exists in the vector or not. I know the below piece of code will check it. #include <algorithm> if ( std::find(vector.begin(), vector.end(), item) != vec...
Hurdygurdy asked 8/3, 2019 at 6:37

3

Solved

Let's say I have a std::any object which may or may not contain a pointer to some derived class of a given base class B. Is there any way I can do something that: Returns a B *, if the std::any o...
Hix asked 5/11, 2019 at 19:15

1

Solved

I'd like to initialize std::any with a move only type variable. I found Cannot move std::any. Compile error case Before I use shared_ptr workaround from the linked answer, I tested the following...
Dougald asked 13/9, 2019 at 12:21

1

Solved

I was trying some things and came to the following question: Is there a possibility to store references to a value in a std::any? I tried the following approaches: #include <any> #include &...
Vern asked 15/6, 2019 at 18:30

1

Solved

The following code using vptr = std::vector<std::unique_ptr<int>>; auto m = std::unordered_map<int, std::any>{}; m.try_emplace(0, move(vptr{})); Fails to compile, complaining a...
Pentacle asked 29/5, 2019 at 22:12

3

Solved

C++17 presents std::variant and std::any, both able to store different type of values under an object. For me, they are somehow similar (are they?). Also std::variant restricts the entry types, be...
Campaign asked 25/5, 2019 at 10:25

4

Solved

Since C++17 std::any is introduced. One can now write code like this #include <iostream> #include <any> #include <string> int main () { const double d = 1.2; std::any var = d;...
Carew asked 9/10, 2018 at 7:10

2

Solved

Is there any way to get the size (in bytes) of the data stored by std::any? The only workaround I came up with is querying the type of its value by std::any::type and comparing the result to a list...
Goings asked 9/4, 2018 at 10:24

1

I have an object which holds a unique_ptr and as such can't be copy constructed without doing a deep copy (which I don't want). I'd like to have std::any hold that object, but the only alternatives...
Equipoise asked 20/10, 2017 at 15:14

4

Solved

I am using C++ in Xcode version 8.1. I need to use the functionality of boost::any but am strongly opposed to pulling any part of Boost into our project (let's not debate it please). I see that st...
Sokotra asked 11/12, 2016 at 20:21

1

Solved

I am toying around with c++17 and plugins, and I have run into an error that I cannot get around. In the following MWE I can call a local function that takes a std::any, and everything works as exp...
Matriarchate asked 10/6, 2017 at 2:17

1

Solved

I was reading the documentation for std::any_cast and I find it strange that the API has the cast either return a value to the held object or a pointer to it. Why not return a reference? A copy nee...
Chaldean asked 28/1, 2017 at 2:50

4

Solved

for example boost::function is moved almost entirely to std::function, the same is with boost::shared_ptr But I can't find std::any? Was it renamed or was not it placed in new standard at all by a...
Sideling asked 8/2, 2012 at 14:19

2

Solved

So, suppose I want to type erase using type erasure. I can create pseudo-methods for variants that enable a natural: pseudo_method print = [](auto&& self, auto&& os){ os << ...
Pasta asked 8/8, 2016 at 18:4

3

The standard working draft (n4582, 20.6.3, p.552) states the following suggestion for implementations of std::any: Implementations should avoid the use of dynamically allocated memory for a smal...
Fondness asked 7/5, 2016 at 23:30
1

© 2022 - 2024 — McMap. All rights reserved.