Skip to content

tl::optional comparison operators do not work with template checks #58

@SeverinTobler

Description

@SeverinTobler

Checking with templates whether tl::optional<T> is comparable returns the wrong result, if T is not comparable (check works with std::optional). For example:

#include <experimental/type_traits>

template <typename T, typename U>
using equality_comparison = decltype(std::declval<T const&>() == std::declval<U const&>());

struct NoCompare {}; // lacks comparison operators

// this assert fails, but equal comparison with tl::optional<NoCompare> doesn't compile
static_assert(!std::experimental::is_detected<equality_comparison, tl::optional<NoCompare>, NoCompare>::value,
              "'tl::optional<NoCompare> == NoCompare' should not compile");

Note: I ran into this issue using tl::optional with Trompeloil (https://github.com/rollbear/trompeloeil), as Trompeloil checks this way whether function parameters are comparable to nullptr.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions