Hi All,
I have an accumulator (a) that takes an initial value (x_), and another
(b), whose initial value (x_) depends on that of (a). I would have
thought that this is feasible because accumulator_set initializes (a)
before (b), but apparently b.x_ is initialized with a garbage value.
namespace impl
{
template
class accu_a_impl : public accumulator_base
{
public:
typedef Sample result_type;
template<typename Args>
accu_a_impl(Args const &args)
:x_(
args[kwd<Id>::value]
)
{
}
result_type result(dont_care) const
{
return x_;
}
private:
result_type x_;
};
}
namespace tag
{
template <typename Id = mpl::void_>
struct accu_a : depends_on<>
{
typedef accumulators::impl::accu_a_implmpl::_1,Id impl;
};
}
namespace impl
{
template
class accu_b_impl
: public accumulator_base
{
typedef tag::accu_a<Id1> a_type;
public:
typedef Sample result_type;
template<typename Args>
accu_b_impl(Args const &args)
:x_(
extract_result(args[accumulator]) // faulty?
)
{
}
template<typename Args>
void operator ()(Args const &args)
{
// overrides initialization for the sake of testing
x_ = extract_result(args[accumulator]);
}
private:
result_type x_;
};
}
namespace tag
{
template
struct accu_b
: depends_on
{
typedef accumulators::impl::accu_b_implmpl::_1,Id0,Id1 impl;
};
}
*.cpp
typedef mpl::size_t<0> id0;
typedef mpl::size_t<1> id1;
typedef double value_type;
typedef tag::accu_a<id0> a_type;
typedef tag::accu_b b_type;
typedef accumulator_set<
value_type,
stats<
b_type
>
> set_type;
set_type set(
(
kwd<id0>::value = 0.9
)
);
std::cout << "a.x_=" << extract_result(set) << std::endl;
std::cout << "b.x_=" << extract_result(set) << std::endl;
set(0);
std::cout << "b.x_=" << extract_result(set) << std::endl;
//Output:
//a.x_=0.9
//b.x_=0.1 // where 0.9 is expected
//b.x_=0.9