1

Currently my library uses boost::optional and boost::variant. Since C++17 is out, I would like to add an option, that it works with the boost and std.

So I tested the complete code with boost optional and variant and std optional and variant successful.

So I added a header files that is similar to this:

#ifdef USE_BOOST
#include <boost/optional.hpp>
#elif USE_STD
#include <optional>
#endif

namespace Foo {

#ifdef USE_BOOST
template <typename T>
using optional = boost::optional<T>
#elif USE_STD
template <typename T>
using optional = std::optional<T>
#endif

}

And everything works stil fine.

Then I added something similar for variant

#ifdef USE_BOOST
#include <boost/variant.hpp>
#elif USE_STD
#include <variant>
#endif

namespace Foo {

#ifdef USE_BOOST
template <typename... T>
using variant = boost::variant<T...>
// similar to the following
#elif USE_STD

template <typename...T>
using variant = std::variant<T...>;

template <class T, class... Types>
constexpr T& get(std::variant<Types...>& v) {
    return std::get<T>(v);
};

template <class T, class... Types>
constexpr T&& get(std::variant<Types...>&& v) {
    return std::get<T>(std::move(v));
};

template <class T, class... Types>
constexpr const T& get(const std::variant<Types...>& v) {
    return std::get<T>(v);
};

template <class T, class... Types>
constexpr const T&& get(const std::variant<Types...>&& v) {
    return std::get<T>(std::move(v));
};

#endif

}

And within the library I use now everywhere Foo::optional and Foo::variant. But now all function templates like

template <typename... Args>
bool bar(const std::tuple<variant<Args,
                                  std::exception_ptr>...>& args)

are not found any more. (clang error message: no matching function for call to ...)

Tested with clang trunk and VS 2017 15.6.1 Preview Any idea?

Many thanks in advance!

Edit: A minimal example is in my gist

Felix Petriconi
  • 675
  • 5
  • 11
  • 2
    Can you provide a [mcve]? – aschepler Jan 20 '18 at 20:55
  • 1
    Many facilities provided by Boost became a part of the standard, but most are changed in the process and will never be fully compatible. You have to deal with it. –  Jan 20 '18 at 20:55
  • std::tuple is already part of C++11 and so there was never a reason to use it from boost. And as I stated at the beginning the complete code works fine without an alias. So when I use std::variant or boost variant. Only the alias does not compile. – Felix Petriconi Jan 20 '18 at 20:58
  • Minimal problem added. – Felix Petriconi Jan 20 '18 at 21:24
  • Don't see the problem http://coliru.stacked-crooked.com/a/3eb0fb2595a7c328 – sehe Jan 20 '18 at 23:59

1 Answers1

0

Finally problem solved. It is a bug in clang an VS. GCC compiles it fine. The solution for clang and VS is calling the function with explicit template parameters.

Felix Petriconi
  • 675
  • 5
  • 11