edouarda/brigand

at_c and lists with reference types

ericniebler opened this issue · 3 comments

namespace brigand
{
  namespace detail
  {
    template<class T> struct element_at;
    template<class... Ts>
    struct element_at<list<Ts...>>
    {
      template<class T> T static at(Ts..., T*, ...);
    };
    template<std::size_t N, typename Seq> struct at_impl;
    template<std::size_t N, template<typename...> class L, class... Ts>
    struct at_impl<N,L<Ts...>>
    {
      using type = decltype(element_at<brigand::filled_list<void const *, N>>::at(static_cast<Ts*>(nullptr)...));
    };
  }
  template <class L, std::size_t Index>
  using at_c = typename detail::at_impl<Index, L>::type;

There's no way that this works if the list has a reference type in it since it forms a pointer to a reference, which is ill-formed.

This looks like case for our good old type_<> bundler, @edouarda what do you think ?

I think I wanted to type "1st" but you stole me that pleasure. 😐

Apart from that, yes we should use the for_each trick of type_<>

https://github.com/edouarda/brigand/blob/master/brigand/types/type.hpp