17 Ekim 2017 Salı

variant recursive_wrapper

Giriş
Şu satırı dahil ederiz.
#include <boost/variant.hpp>
Açıklaması şöyle
The recursive_wrapper<T> always represents a heap-allocated instance of T, and it does not have an empty state.
Açıklaması şöyle
Recursive wrapper is normally used for the case that T is an incomplete type at the time that you declare the variant. For instance, what if this variant needs to be a member of large_struct.

recursive_wrapper<T> is internally just a pointer T*, but the variant is aware of this pointer and transparently dereferences it for you. This is for when the fact that it needs to be a pointer is a "detail" that you don't want the user to have to think about.
Örnek
Şöyle yaparız.
using v = boost::variant<int, boost::recursive_wrapper<struct s> >;
struct s
{
  v val;
};
Örnek
Şöyle yaparız.
struct mini_xml;

typedef
    boost::variant<
        boost::recursive_wrapper<mini_xml>
      , std::string
    >
mini_xml_node;

struct mini_xml
{
  std::string name;                           // tag name
  std::vector<mini_xml_node> children;        // children
};
Örnek
Variant'ımız çok büyük olsun.
boost::variant<int,double,large_struct>>
Küçültmek için şöyle yaparız.
boost::variant<int,double,boost::recursive_wrapper <large_struct>>>


Hiç yorum yok:

Yorum Gönder