+ 4

Differences between std::any and auto...

I recently came across the std::any class, recently introduced in C++17, based on boost::any. From the en.cppreference.com 's reference [ en.cppreference.com/w/cpp/utility/any ], I read that this class can 'hold an instance of any type'. What does that mean? Is it like C++11's auto which can deduce a type for a variable or better? Or is it something else? Kindly enlighten me on this.

24th Feb 2018, 10:36 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
3 Antworten
+ 10
24th Feb 2018, 10:53 AM
jay
jay - avatar
+ 9
yep :) it is basically a copy of this: https://theboostcpplibraries.com/boost.any
24th Feb 2018, 11:05 AM
jay
jay - avatar
+ 2
I can see that one cannot use std::any without casting it to the required type with std::any_cast, but it really can hold anything, anytime. Thank you very much!
24th Feb 2018, 11:02 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar