トルネード

毛利のメモ書き

メタプログラミング File Monkey mpl::vectorを使う

boost::mpl を使ってFile MonkeyやVCLDelphiオブジェクトをメタプログラミング実装する

mpl::vector, mpl::at_c, mpl::if_cを使った。

インクルード

#include <fmx.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
#include <boost/mpl/vector.hpp>
#include <boost/mpl/at.hpp>
#include <boost/mpl/if.hpp>
#include <memory>

実装部

__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
    namespace  mpl = boost::mpl;

    using v = mpl::vector<TButton, TPanel>;
    using mplobj = mpl::at_c<v, 1>::type; //これで呼べる

    using ifobj = mpl::if_c< //if_cを使う
        false, mpl::at_c<v, 0>::type, mplobj
        >::type;

    std::shared_ptr<ifobj> obj1(new ifobj(this));
    this->AddObject(obj1.get());
}

これshared_ptrでobj1を作ったので抜けると消えるw(当然) この場合のARCはどうなるのか気になる

Automatic Reference Counting in C++ - RAD Studio