Здравствуйте, _nn_, Вы писали:
Нашел некрасивый хак
, value_type можно достать у первого элемента последовательности.
В случае transform — item0::value_type, а в случае joint_view — sequence1_::item0::value_type, и соответственно переделать c_str:
#include <boost/mpl/vector_c.hpp>
#include <boost/mpl/char.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/mpl/plus.hpp>
#include <boost/mpl/string.hpp>
#include <boost/mpl/joint_view.hpp>
#include <iostream>
struct get_value_type_item0
{
template<typename Sequence>
struct apply
{
typedef typename Sequence::type::item0::value_type value_type;
};
};
struct get_value_type_sequence1_item0
{
template<typename Sequence>
struct apply
{
typedef typename Sequence::type::sequence1_::item0::value_type value_type;
};
};
template<typename Sequence, typename ValueTypeGetter>
struct c_str_tmp
{
typedef typename boost::mpl::end<Sequence>::type iend;
typedef typename boost::mpl::begin<Sequence>::type i0;
#define M0(z, n, data) \
typedef \
typename boost::mpl::aux_::next_unless<BOOST_PP_CAT(i, n), iend>::type \
BOOST_PP_CAT(i, BOOST_PP_INC(n));
BOOST_PP_REPEAT(BOOST_MPL_LIMIT_STRING_SIZE, M0, ~)
#undef M0
typedef c_str_tmp type;
typedef typename ValueTypeGetter::template apply<Sequence>::value_type value_type;
static value_type const value[BOOST_MPL_LIMIT_STRING_SIZE+1];
};
template<typename Sequence, typename ValueTypeGetter>
typename c_str_tmp<Sequence, ValueTypeGetter>::value_type const c_str_tmp<Sequence, ValueTypeGetter>::value[BOOST_MPL_LIMIT_STRING_SIZE+1] =
{
#define M0(z, n, data) \
boost::mpl::aux_::deref_unless<BOOST_PP_CAT(i, n), iend>::type::value,
BOOST_PP_REPEAT(BOOST_MPL_LIMIT_STRING_SIZE, M0, ~)
#undef M0
'\0'
};
using namespace boost::mpl;
typedef vector_c<char, 'a', 'b', 'c', 'd'> z;
const char* zc = c_str<z>::value;
// Transform
typedef transform<
z,
plus<_, char_<1> >
>::type z1;
const char* z1c = c_str_tmp<z1, get_value_type_item0>::value;
// Join View
typedef joint_view<
z1,
z1
>::type z1z1;
const char* z1z1c = c_str_tmp<z1z1, get_value_type_sequence1_item0>::value;
int main()
{
std::cout << z1c << "\n"; // bcde
std::cout << z1z1c << "\n"; // bcdebcde
}