编译boost.spirit.karma示例,customize_embedded_container.cpp失败

compiling boost.spirit.karma example, customize_embedded_container.cpp fails

本文关键字:embedded container cpp 失败 customize boost spirit karma 示例 编译      更新时间:2023-10-16

使用GCC或Clang最新,Boost 1.68(OR 1.69),

编译boost.spirit.karma示例customize_embedded_container.cpp失败,除非在第26行中用value_type替换类型。

另一个有用的示例,customize_use_as_container.cpp也失败了,要求value_type等。在indirect_iterator中,"没有命名类型'value_type'在'std :: iterator_traits'

有关引用的示例:https://www.boost.org/doc/libs/1_69_0/libs/spirit/spirit/example/karma/customize_use_ase_as_container.container.cppp

  • 有任何线索或工作示例用于集装箱特殊化的示例

鉴于我的情况,解决方案的骨架,或者只是在boost中很容易效法的零件。

namespace X {
  struct p { double t,v;};// point, time, value
  struct ts { // simplified time-series representation, time-axis computed
     bool s;
     double t0,dt;size_t n;// ti = t0 + dt*i
     std::vector<double> v;// v.size()===n
     p point(size_t i ) const  { return p{t0+dt*i,v[i]};}
  };
  //--would like to output grammar like {pfx:(true|false),data:[[t,v]..]}
  //--; first construct a container class out of ts, using boost iterator_facade 
  //--; to get away with few lines.(simplified..)
  struct ts_c {
     using value_type=p;// iterate over (t,v), t is computed, v is plain vector
     ts * c;
     struct iterator:public::boost::iterator_facade<iterator,p,boost::random_access_traversal..> { //..
       iterator(ts*c,size_t pos=0u):c{c},pos{pos} {}
        //.. plain vanilla impl. goes here according to boost::iterator_facade.
       private:
         ts* c;
         size_t pos;
     };
     using const_iterator=iterator;
     iterator begin() const;//.. etc. impl. of need it stuff.
  };
}
// use FUSION to adapt the ts-type, let last tuple member return the
// tuple members:
// 0 true if n>0, otherwise false
// 1 true if ts.s is true
// 2 returns a vanilla iterable container, ts_c exposing type p
BOOST_FUSION_ADAPT_ADT(
    X::ts,
    (bool,bool, obj.n>0,/**/)
    (bool,bool,obj.s,/**/)
    (X::ts_c,X::ts_c, X::ts_c(&obj),/**/)
)
//-- then combining the boost spirit complex example to emit the point class p
namespace X {
    namespace ka=boost::spirit::karma;
    /** generate a point like [123.0, 3.14], or [123.0,null] if !isfinite. 
    *  using the complex example pattern given in boost::spirit,
    */
    template<class OutputIterator>
    struct point_generator:ka::grammar<OutputIterator,p()> {
        point_generator():point_generator::base_type(pg) {
            using ka::true_;
            using ka::bool_;
            using ka::omit;
            pg = 
                &true_ <<( '[' <<  double_<< ',' << double_ << ']')
                    |
                      omit[bool_]<<   ( '[' <<  double_<< ',' << "null" << ']')
            ;
        }
        ka::rule<OutputIterator,p()> pg;
    };
    /** @brief a ts generator
    *
    * outputs:
    *   {pfx:(true|false),data:[[t,v],..]}
    * or if empty
    *   {pfx:null,data:null}
    */
    template<class OutputIterator>
    struct ts_generator:ka::grammar<OutputIterator,ts()> {
        ts_generator():ts_generator::base_type(tsg) {
            using ka::true_;
            using ka::bool_;
            using ka::omit;
            tsg =
                &true_ <<"{pfx:"<<bool_<<",data:"<<( '[' << pt_ % ',' << ']')<<'}'
                    |
                      omit[bool_]<<  "{pfx:null: data:null}"
            ;
        }
        ka::rule<OutputIterator,ts()> tsg;
        point_generator<OutputIterator> pt_;
    };
}