I want the following code to compile and work:
#include <boost/hana/group.hpp>
#include <functional>
#include <vector>
int main() {
std::vector<int> x = {1,1,3,4};
auto groups = boost::hana::group(x, std::equal_to<>{});
}
An attempt to compile errors like this:
$ g++ -std=c++2a deleteme.cpp && ./a.out
In file included from deleteme.cpp:1:
/usr/include/boost/hana/group.hpp: In instantiation of ‘constexpr auto boost::hana::group_t::operator()(Xs&&, Predicate&&) const [with Xs = std::vector<int>&; Predicate = std::equal_to<void>]’:
deleteme.cpp:6:44: required from here
/usr/include/boost/hana/group.hpp:55:42: error: static assertion failed: hana::group(xs, predicate) requires 'xs' to be a Sequence
55 | static_assert(hana::Sequence<S>::value,
| ^~~~~
/usr/include/boost/hana/group.hpp:59:28: error: use of deleted function ‘static constexpr auto boost::hana::deleted_implementation::apply(T&& ...) [with T = {std::vector<int, std::allocator<int> >&, std::equal_to<void>}]’
59 | return Group::apply(static_cast<Xs&&>(xs),
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
60 | static_cast<Predicate&&>(pred));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/boost/hana/core/dispatch.hpp:14,
from /usr/include/boost/hana/drop_front.hpp:18,
from /usr/include/boost/hana/concept/iterable.hpp:20,
from /usr/include/boost/hana/at.hpp:16,
from /usr/include/boost/hana/group.hpp:15,
from deleteme.cpp:1:
/usr/include/boost/hana/detail/dispatch_if.hpp:21:31: note: declared here
21 | static constexpr auto apply(T&& ...) = delete;
| ^~~~~
Therefore I understand that the reason is that std::vector
does not satisfy the concept of Sequence
, but how do I enforce that it does?
I've been giving a look at /usr/include/boost/hana/fwd/concept/sequence.hpp
and /usr/include/boost/hana/concept/sequence.hpp
, but for now the template meta-metaprogramming in those files is still a bit to heavy for me to understand it without any help.
This is an excerpt from Hana's documentation, which I think addresses the question. The point is that I don't how I can translate that prescriptions to code:
For this reason, it is necessary to specialize the Sequence metafunction in Hana's namespace to tell Hana that a type is indeed a Sequence. Explicitly specializing the Sequence metafunction can be seen like a seal saying "this data type satisfies the additional laws of a
Sequence
", since those can't be checked by Hana automatically.