Skip to content

Commit

Permalink
with: add sfinae for nicer compile failure messages
Browse files Browse the repository at this point in the history
Had we not been operating in the context of a CRTP, the sfinae would
have been:

```
template <typename T,
  std::enable_if_t<
    std::is_same_v<
      T,
      typename decltype(std::decval<Deriv>().make())::value_type
    >
  , int> = 0
>
```

However, this cannot work, for then compilers will complain that we're
referencing an incomplete type in the form of std::declval<Deriv>.

We need to delay the type instantiation with the following form:

```
template <typename T,
  typename U = Deriv,
  std::enable_if_t<
    std::is_same_v<
      T,
      typename decltype(std::decval<U>().make())::value_type
    >
  , int> = 0
>
```

As far as I can tell, it's essentially this problem:

https://stackoverflow.com/questions/43307462
  • Loading branch information
TheCoconutChef committed Oct 21, 2022
1 parent 6c63e7b commit ba9d8e4
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lager/with.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,14 @@ class with_expr_base : public xform_mixin<Deriv>
return deriv_().zoom(lens);
}

template <typename T>
template <typename T,
typename U = Deriv,
std::enable_if_t<
std::is_same_v<
typename decltype(std::declval<U>().make())::value_type,
T
>,
int> = 0>
operator reader<T>() &&
{
return std::move(*this).make();
Expand All @@ -182,7 +189,14 @@ class with_expr_base : public xform_mixin<Deriv>
{
return std::move(*this).make();
}
template <typename T>
template <typename T,
typename U = Deriv,
std::enable_if_t<
std::is_same_v<
typename decltype(std::declval<U>().make())::value_type,
T
>,
int> = 0>
operator cursor<T>() &&
{
return std::move(*this).make();
Expand Down

0 comments on commit ba9d8e4

Please sign in to comment.