TartanLlama / optional

C++11/14/17 std::optional with functional-style extensions and reference support
https://tl.tartanllama.xyz
Creative Commons Zero v1.0 Universal
859 stars 67 forks source link

Conflicting implementations of map_imp in optional.hpp and expected.hpp #5

Closed jeroen-dhollander closed 6 years ago

jeroen-dhollander commented 6 years ago

Hey,

I am using both your implementation for optional and expected in the same project, and I got compile issues when including both in the same file and using map on either of them:

// Minimal code to expose this:
#include "expected.hpp"
#include "optional.hpp"

void MyFunction()
{
    tl::optional<int> my_optional;
    my_optional.map([](int value) { return value + 1; });
}

Compilation failure:

optional.h: In instantiation of 'constexpr auto tl::optional<T>::map(F&&) & [with F = MyFunction()::<lambda(int)>; T = int]':
file.cc:14:56:   required from here
optional.h:770:20: error: call of overloaded 'map_impl(tl::optional<int>&, MyFunction()::<lambda(int)>)' is ambiguous
     return map_impl(*this, std::forward<F>(f));
            ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~

The problem is that both optional and expected use a helper called map_impl, but with different implementations.

A simple solution I applied is simply renaming map_impl to optional_map_impl and expected_map_impl, respectively.

Jeroen

PS Thanks a lot for these libraries, I love them :)

TartanLlama commented 6 years ago

Whoops, I missed this issue, will get a fix up ASAP.

TartanLlama commented 6 years ago

Should be fixed in https://github.com/TartanLlama/optional/commit/74a422b824f308f2e9230307c44070e0efb85eef and https://github.com/TartanLlama/expected/commit/fcd78565df9af5a327d26b150b06639cca9d768e

jeroen-dhollander commented 6 years ago

Thanks