Questions tagged [stdany]

The class any is a type-safe container for single values of any type.

Class any is included into C++ 17 standard, see here. It is a container for single values of any type.

Functions any_cast provides access to contained object.

72 questions
0
votes
1 answer

std::any for move-only template where static_assert inside copy-ctor equals compile error, but why?

I don't see why move-only templates can not be extended by copy-ctor having a static_assert (like in the code below) in order to be used with std::any #include #include namespace detail{ template struct MoveOnly { …
ezegoing
  • 526
  • 1
  • 4
  • 18
0
votes
1 answer

Reading sub-object vector with rapidjson

This is my json: { "data": { "text": "hey stackoverflow", "array_1": [ ["hello", "world", 11, 14] ] }, } I have managed to extract the text attribute like so: Code: document.Parse(request_body); auto&…
lifeguru42
  • 156
  • 1
  • 12
0
votes
1 answer

How to expand a parameter pack into a vector

Compile problem error: no matching constructor for initialization of 'std::vector' The code base I am building has several objects that do not need to be variadic template parameters. I wanted to make them accept a vector of std::any. My objects are…
0
votes
1 answer

Cannot move std::any

The following code using vptr = std::vector>; auto m = std::unordered_map{}; m.try_emplace(0, move(vptr{})); Fails to compile, complaining about using of deleted copy constructor of unique_ptr. After replacing…
Ryba
  • 681
  • 4
  • 13
0
votes
2 answers

Storing multiple types into class member container

I was reading this Q/A here and as my question is similar but different I would like to know how to do the following: Let's say I have a basic non template non inherited class called Storage. class Storage {}; I would like for this class to have a…
Francis Cugler
  • 7,788
  • 2
  • 28
  • 59
0
votes
1 answer

Will it be possible to compare two arbitrary functions with std::any in C++17?

I think it is a big limitation of how C++ handles function pointers and std::function, that it is currently impossible to compare two arbitrary functions of different type in an elegant way. I am now wondering if C++17 will change that with the…
N0vember
  • 995
  • 1
  • 9
  • 12
-1
votes
1 answer

Transfer data from library to upper level and then back without naming it inbetween

I need to get some complex data from a library then use this data at the upper level. The data consists of 2 parts: while evaluating the data A, i get some additional data B, and the data B should be returned back in the library "as is" in order to…
tester
  • 43
  • 2
  • 8
-1
votes
2 answers

How to correctly check any_cast available?

I have some input which can be simple value or container, packed in std::any. I don't want to use exceptions, so I call noexcept variadic any_cast method which return pointer or nullptr to value of any. I can verify any cast available with typeid()…
-1
votes
1 answer

Use std::map with std::any as value type

I'd like to have class Config able to store literally any value within a string key. For that purpose it seems that std::map fits. Unfortunately this isn't compiling. That looks like that std::is_copy_constructible> trait…
-1
votes
1 answer

unordered_map with std::any values cannot any_cast string

I'm new to C++ and I was studying about std::unordered_map and std::any. I've created a sample demo bellow which generates some dummy data and then they get inserted into the map. After that (in the commented out code) I print out the values using…
0x_Anakin
  • 3,229
  • 5
  • 47
  • 86
-2
votes
2 answers

How to Add Element into a std::vector using std::any

I am working on a C++17 project and there i am using std::any. A minimal reproducible example is given below for reference explaining what i want to achieve. #include #include #include int main() { std::vector
user16783784
-2
votes
2 answers

Is std::any supported in MSVC 2017?

I try to compile a piece of code with: cl /c /std:c++latest /Gm- /sdl /Zc:inline /RTC1 /Oy /MDd /FA /EHs main.cxx but I get this error: error C2039: 'any': is not a member of 'std' and I wonder how (if possible) can I get to have this feature. I…
bMain
  • 324
  • 3
  • 11
1 2 3 4
5