About "any type" in C++11[JAPAN]
About "any type" in C++11[JAPAN]
C++1z(C++17) expects "std::any" to be prepared.
C++Builder(C++11) can use boost. Its version is 1_55.
////
#define BOOST_VERSION 105500
#define BOOST_LIB_VERSION "1_55"
"boost::any" can be used.
////
#include <boost/any.hpp>;
////
void __fastcall TForm1::Button1Click(TObject *Sender)
{
//value of the float
boost::any button_and_float = BOOST_VERSION + 0.0001;
//Place TButton in the same variable.
//But, it does not go out error.
button_and_float = new TButton(this);
//This can be used if the cast. It can be used as Button.
auto button2 = boost::any_cast<TButton* >(button_and_float);
button2->Parent = this;
button2->Top = 200;
button2->Left = 200;
button2->Width = 200;
button2->Name = "Button2";
button2->Caption = "Any Button2";
}
In this way, you can use it.

//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
//value of the float
boost::any button_and_float = BOOST_VERSION + 0.0001;
boost::any event_ = static_cast<void*>([](TObject* Sender){ShowMessage("event");});
TMethod method_;
method_.Data = nullptr;
method_.Code = boost::any_cast<void* >(event_);
//Place TButton in the same variable.
//But, it does not go out error.
button_and_float = new TButton(this);
//This can be used if the cast. It can be used as Button.
auto button2 = boost::any_cast<TButton* >(button_and_float);
button2->Parent = this;
button2->Top = 200;
button2->Left = 200;
button2->Width = 200;
button2->Name = "Button2";
button2->Caption = "Any Button2";
button2->OnClick = reinterpret_cast<TNotifyEvent&>(method_);
}
