These are chat archives for boostorg/hana

18th
Nov 2015
Jason Rice
@ricejasonf
Nov 18 2015 02:29
struct FindByKey
{
/*
  template<typename Xs, typename Key>
  constexpr decltype(auto) operator()(Xs&& xs, const Key& key) const
  {
    return hana::second(hana::find_if(static_cast<Xs&&>(xs), 
      hana::on(hana::equal.to(key), hana::first)).value()); 
  }
*/
  template<typename Xs, typename Key>
  constexpr decltype(auto) operator()(Xs&& xs, const Key& key) const
  {
    using Pack = typename hana::detail::make_pack<Xs>::type;
    using Pred = decltype(hana::compose(hana::equal.to(key), hana::first));
    constexpr std::size_t index = hana::detail::index_if<Pred, Pack>::value;
    return hana::second(hana::at_c<index>(static_cast<Xs&&>(xs)));
  }
};
my first attempt wasn't working with references
second one should probably look familiar :P
Louis Dionne
@ldionne
Nov 18 2015 03:47
@ricejasonf Lol. find_if should work with reference, it’s arguably a bug. See boostorg/hana#175. As for FindByKey, it’s a good implementation but it’s also a bit tricky since it uses implementation details. Oh well, you know what you’re doing :)