• <i id='WUtPo'><tr id='WUtPo'><dt id='WUtPo'><q id='WUtPo'><span id='WUtPo'><b id='WUtPo'><form id='WUtPo'><ins id='WUtPo'></ins><ul id='WUtPo'></ul><sub id='WUtPo'></sub></form><legend id='WUtPo'></legend><bdo id='WUtPo'><pre id='WUtPo'><center id='WUtPo'></center></pre></bdo></b><th id='WUtPo'></th></span></q></dt></tr></i><div id='WUtPo'><tfoot id='WUtPo'></tfoot><dl id='WUtPo'><fieldset id='WUtPo'></fieldset></dl></div>

      <bdo id='WUtPo'></bdo><ul id='WUtPo'></ul>
    <tfoot id='WUtPo'></tfoot>

        <legend id='WUtPo'><style id='WUtPo'><dir id='WUtPo'><q id='WUtPo'></q></dir></style></legend>
      1. <small id='WUtPo'></small><noframes id='WUtPo'>

        序列化原始 boost::variant 是否安全?

        Is it safe to serialize a raw boost::variant?(序列化原始 boost::variant 是否安全?)
          <tbody id='iUv7W'></tbody>

            • <bdo id='iUv7W'></bdo><ul id='iUv7W'></ul>

              1. <legend id='iUv7W'><style id='iUv7W'><dir id='iUv7W'><q id='iUv7W'></q></dir></style></legend>
              2. <tfoot id='iUv7W'></tfoot>

                <small id='iUv7W'></small><noframes id='iUv7W'>

                • <i id='iUv7W'><tr id='iUv7W'><dt id='iUv7W'><q id='iUv7W'><span id='iUv7W'><b id='iUv7W'><form id='iUv7W'><ins id='iUv7W'></ins><ul id='iUv7W'></ul><sub id='iUv7W'></sub></form><legend id='iUv7W'></legend><bdo id='iUv7W'><pre id='iUv7W'><center id='iUv7W'></center></pre></bdo></b><th id='iUv7W'></th></span></q></dt></tr></i><div id='iUv7W'><tfoot id='iUv7W'></tfoot><dl id='iUv7W'><fieldset id='iUv7W'></fieldset></dl></div>

                  本文介绍了序列化原始 boost::variant 是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  boost::variant 声称它是一种值类型.这是否意味着简单地写出 boost::variant 的原始表示并稍后加载它是安全的,只要它只包含 POD 类型?假设它将由相同编译器和相同版本的 boost 编译的代码在相同的架构上重新加载.

                  boost::variant claims that it is a value type. Does this mean that it's safe to simply write out the raw representation of a boost::variant and load it back later, as long as it only contains POD types? Assume that it will be reloaded by code compiled by the same compiler, and same version of boost, on the same architecture.

                  另外,(可能)等价地,boost::variant 可以用在共享内存中吗?

                  Also, (probably) equivalently, can boost::variant be used in shared memory?

                  推荐答案

                  关于序列化:它应该有效,是的.但是为什么不使用boost::variant的访问机制来写出variant中包含的实际类型呢?

                  Regarding serialisation: It should work, yes. But why don't you use boost::variant's visitation mechanism to write out the actual type contained in the variant?

                  struct variant_serializer : boost::static_visitor<void> {
                      template <typename T>
                      typename boost::enable_if< boost::is_pod<T>, void>::type
                      operator()( const T & t ) const {
                          // ... serialize here, e.g.
                          std::cout << t;
                      }
                  };
                  
                  int main() {
                  
                      const boost::variant<int,char,float,double> v( '1' );
                  
                      variant_serializer s;
                      boost::apply_visitor( s, v );
                  
                      return 0;
                  }
                  

                  关于共享内存:boost::variant 不执行堆分配,所以你可以像 int 一样将它放入共享内存,当然,假设适当的同步.

                  Regarding shared memory: boost::variant does not perform heap allocations, so you can place it into shared memory just like an int, assuming proper synchronisation, of course.

                  不用说,正如您所说,以上仅当变体只能包含 POD 类型时才有效.

                  Needless to say, as you said, the above is only valid if the variant can only contain POD types.

                  这篇关于序列化原始 boost::variant 是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
                  Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
                  STL BigInt class implementation(STL BigInt 类实现)
                  Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
                  Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
                  Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)
                  <i id='yPXuF'><tr id='yPXuF'><dt id='yPXuF'><q id='yPXuF'><span id='yPXuF'><b id='yPXuF'><form id='yPXuF'><ins id='yPXuF'></ins><ul id='yPXuF'></ul><sub id='yPXuF'></sub></form><legend id='yPXuF'></legend><bdo id='yPXuF'><pre id='yPXuF'><center id='yPXuF'></center></pre></bdo></b><th id='yPXuF'></th></span></q></dt></tr></i><div id='yPXuF'><tfoot id='yPXuF'></tfoot><dl id='yPXuF'><fieldset id='yPXuF'></fieldset></dl></div>
                  <legend id='yPXuF'><style id='yPXuF'><dir id='yPXuF'><q id='yPXuF'></q></dir></style></legend>

                      • <bdo id='yPXuF'></bdo><ul id='yPXuF'></ul>

                        <tfoot id='yPXuF'></tfoot>
                        • <small id='yPXuF'></small><noframes id='yPXuF'>

                              <tbody id='yPXuF'></tbody>