Skip to content

Commit

Permalink
improve compile time message on assignation failure
Browse files Browse the repository at this point in the history
Consider the following simple program:

```
int main() {
  lager::reader<int> a;
  lager::reader<std::string> b = a;
  return 0;
}
```

Compiling it will produce about many lines of compiler messages, mostly
relating to template deduction failure of a shared_ptr ctor.

This noisy situation is improved by the use of sfinae statements in the
reader to reader ctor and cursor to reader ctor. In this case, an
attempt to compile the aforementioned program will fail with about 4
lines of compiler messages directly quoting the offending line.

N.B. this commit does not cover the case:

```
lager::reader<int> a = lager::with(...);
```
  • Loading branch information
TheCoconutChef committed Oct 21, 2022
1 parent 2c60004 commit 6c63e7b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lager/cursor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ class cursor_base

cursor_base() = default;

template <typename T>
template <typename T,
std::enable_if_t<std::is_same_v<zug::meta::value_t<NodeT>,
zug::meta::value_t<T>>,
int> = 0>
cursor_base(cursor_base<T> x)
: base_t{std::move(x)}
{}
Expand Down
10 changes: 8 additions & 2 deletions lager/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,18 @@ class reader_base

reader_base() = default;

template <typename T>
template <typename T,
std::enable_if_t<std::is_same_v<zug::meta::value_t<NodeT>,
zug::meta::value_t<T>>,
int> = 0>
reader_base(reader_base<T> x)
: base_t{std::move(x)}
{}

template <typename T>
template <typename T,
std::enable_if_t<std::is_same_v<zug::meta::value_t<NodeT>,
zug::meta::value_t<T>>,
int> = 0>
reader_base(cursor_base<T> x)
: base_t{std::move(x)}
{}
Expand Down
4 changes: 3 additions & 1 deletion lager/watch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ class watchable_base : private NodeT::signal_type::forwarder_type
: node_{std::move(p)}
{}

template <typename T>
template <typename T,
std::enable_if_t<std::is_same_v<value_t, zug::meta::value_t<T>>,
int> = 0>
watchable_base(watchable_base<T> x)
: node_(std::move(x.node_))
{}
Expand Down

0 comments on commit 6c63e7b

Please sign in to comment.