TRIQS / triqs

a Toolbox for Research on Interacting Quantum Systems
https://triqs.github.io
GNU General Public License v3.0
141 stars 72 forks source link

Fix constraints not satisfied in template argument deduction #951

Closed hmenke closed 3 months ago

hmenke commented 3 months ago

Since C++23 the signature of std::apply has changed ^1 to

template< class F, tuple-like Tuple >
constexpr decltype(auto) apply( F&& f, Tuple&& t ) noexcept(/* see below */);

where tuple-like is required to be a specialization of std::array, std::tuple, std::pair, or std::ranges::subrange ^2. However, prod_mesh_point_t only derives from std::tuple and therefore does not satisfy the tuple-like concept.

This results in compiler errors similar to (here GCC 14)

c++/triqs/././mesh/prod.hpp:42:42: error: no matching function for call to ‘apply(triqs::mesh::prod_mesh_point<triqs::mesh::cyclat, triqs::mesh::dlr>::<lambda(auto:163& ...)>, triqs::mesh::prod_mesh_point<triqs::mesh::cyclat, triqs::mesh::dlr>&)’
   42 |     index_t _index           = std::apply([](auto &...x) { return std::make_tuple(x.index()...); }, *this);
      |                                ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14.1.0/tuple:2931:5: note: candidate: ‘template<class _Fn, class _Tuple>  requires  __tuple_like<_Tuple> constexpr decltype(auto) std::apply(_Fn&&, _Tuple&&)’
 2931 |     apply(_Fn&& __f, _Tuple&& __t)
      |     ^~~~~
/usr/include/c++/14.1.0/tuple:2931:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14.1.0/tuple:2931:5: note: constraints not satisfied
/usr/include/c++/14.1.0/bits/stl_pair.h: In substitution of ‘template<class _Fn, class _Tuple>  requires  __tuple_like<_Tuple> constexpr decltype(auto) std::apply(_Fn&&, _Tuple&&) [with _Fn = triqs::mesh::prod_mesh_point<triqs::mesh::cyclat, triqs::mesh::dlr>::<lambda(auto:163& ...)>; _Tuple = triqs::mesh::prod_mesh_point<triqs::mesh::cyclat, triqs::mesh::dlr>&]’:

Casting back to the base class tuple_t resolves the issue.