
This is what ADL (argument dependent lookup) is for: https://en.cppreference.com/w/cpp/language/adl See e.g. https://compiler-explorer.com/z/oej1ehhnY template <typename T> T foo(T x) { using std::sin; return sin(x) * 42; } int main() { using A = double; using B = boost::multiprecision::cpp_bin_float_oct; A a = foo(A(23)); // ok B b = foo(B(23)); // ok std::cout << std::setprecision(32); std::cout << "a: " << a << "\n"; std::cout << "b: " << b << "\n"; using std::abs; std::cout << "|b-a|: " << abs(b-a) << "\n"; } As you'd expect, b is more precise than a: a: -35.541256975357164549222943605855 b: -35.541256975357166680135703420035 |b-a|: 2.1309127598141799216575314028644e-15 Seth On Sun, Apr 16, 2023, at 9:02 PM, Gero Peterhoff via Boost wrote:
Hello John, * problem description The functions of boost::multiprecision are not available in std, e.g. template <typename type> Type foo(const Type x) noexcept { return std::sin(x) * 42; }
using A = double; A a = foo(A(23)); // ok
using B = boost::multiprecision::cpp_bin_float_oct; B b = foo(B(23)); // error
As a workaround you currently have to write template <typename Type> Type bar(const Type x) noexcept { using ::std::sin; using ::boost::multiprecision::sin; return sin(x) * 42; }
using A = double; A a = bar(A(23)); // ok
using B = boost::multiprecision::cpp_bin_float_oct; B b = bar(B(23)); // ok
This contradicts the template idea and is time-consuming/error-prone.
thx Gero
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Attachments: * OpenPGP_signature