Boost logo

Boost :

From: Bernard (yahoo_at_[hidden])
Date: 2003-11-17 07:50:21

Le Vendredi 14 Novembre 2003 15:52, Joel de Guzman a écrit :
> Bernard <yahoo_at_[hidden]> wrote:
> >
> > (for example:
> > template<typename N, typename TupleOfTuples>
> > struct select_Nth_view :
> > transform_view<filter_view<tuple_view<TupleOfTuples>, ... >{};
> I think that's a good strategy. Have you tried it?

I came up with the following :

template<typename N>
struct get_element{
  template <typename T>
  struct result : tuple_element<N::value
                                                  , typename boost::remove_reference<T>::type >
// why do I need boost::remove_reference<T>::type ?
template <typename T>
  typename result<T>::type operator()(T x) const
         { return get<N::value>(x) ;}
template<typename N, typename TupleOfTuples>
struct select_view :
                                    , greater<tuple_size<_>, N > >
                                    , get_element<N > > {
  typedef transform_view<filter_view<tuple_view<TupleOfTuples>
                                     , greater< tuple_size<_>, N > >
                         , get_element<N> > parent;
// too bad I have to repeat the parent type :-(
  select_view( TupleOfTuples t)
template<typename ViewT>
struct result_of_generate: tuple_detail::generate_tuple<
    typename ViewT::begin_type
    ,typename ViewT::end_type
int main(int argc, char** argv){

  typedef tuple<
    tuple<int, char, long>
    , tuple<char>
    , tuple<float, long> > input_tuples;
  input_tuples it(make_tuple(10, 'a', 10L)
  int const selectionIndex=1;
  typedef select_view<int_<selectionIndex>, input_tuples>
  my_select_type sel(it);
  result_of_generate<my_select_type>::type myResult(generate(sel));
  return 0;

I was wondering wether it was possible at all and Fusion made it
really easy ! Well done !

I enjoy your tuples so much that I want to use them everywhere. Well
not only that but I also would want everybody to use them everywhere
It seems only logical to me when doing metaprogramming:
You want to work with fonctions, so you have to know things about them
(eg. number and types of arguments). Why would you not decide that
every fonction should only take one argument ? Of course it would be
a tuple. All the ugly code handling differents number of arguments
(and limit on that number) would be factored in tuple. Other meta
programming libs would know that they only have to handle one args,
and they can then query about the number of elements in the tuple
Such a convention must be used across the board to be useful and this
is not possible for classical dynamic C++, but if you are to decide
convention for compile time C++, I do not see any reason not to do
I would also define integral arguments to be wrapped in int_<>
(uint_<> ) for consistency.

I know it my sound strange, but I really think that such a
"restricted" API would only be beneficial, because it would only give
more powerful meta-programming.


PS: Is there a reason not to have
tuple<> make_tuple(){ tuple();} for consistency ?
PS2: Even if you think my idea of using only 1 tuple as argument is
crazy, I think the argument to always have classes modeling Integral
Constant (for example with tuple_element<> still holds.
PS3: Just wanted to say it again : fusion *rocks* :-)

Boost list run by bdawes at, gregod at, cpdaniel at, john at