-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
X3: MSVC unordered containers is_reservable<T>::value == false
#298
Comments
The errors came from reservable-tests of std::unordered_xyz classes. So this is the standard And this is boost But (of course) this is microsoft |
reserve
reserve
is_reservable<T>::value == false
This perfectly compiles on VS 2015, 2017: #include <unordered_map>
#include <unordered_set>
int main()
{
std::unordered_map<int, int> umap;
umap.reserve(1);
std::unordered_set<int> uset;
uset.reserve(1);
std::unordered_multimap<int, int> ummap;
ummap.reserve(1);
std::unordered_multiset<int> umset;
umset.reserve(1);
return 0;
} It should be a problem in traits. |
Would like to find the difference. |
Here is the problem: MSVC unordered containers have a base class unordered_map
: public _Hash<_Umap_traits<_Kty, _Ty,
_Uhash_compare<_Kty, _Hasher, _Keyeq>, _Alloc, false>> but #include <boost/tti/has_member_function.hpp>
#include <iostream>
BOOST_TTI_HAS_MEMBER_FUNCTION(function1);
struct A { int function1(); };
struct B : A {};
int main()
{
std::cout << std::boolalpha
<< has_member_function_function1<A, int>::value << std::endl // 1. true
<< has_member_function_function1<B, int>::value << std::endl // 2. false
;
return 0;
} |
Excellent analysis! |
Possible solution: #include <iostream>
struct A {
void reserve(size_t);
};
struct B : A {};
// For this approach we need a void_t
// We could use std::void_t (but it's c++17)
// Is there something equivalent in boost?!
// If not we can define it by:
template <typename... T> using void_t = void;
template <typename T, typename = void>
struct has_reserve : std::false_type {};
template <typename T>
struct has_reserve<T, void_t<
decltype(std::declval<T&>().reserve(size_t{}))
>> : std::true_type {};
template <typename T, typename = void>
struct has_foo : std::false_type {};
template <typename T>
struct has_foo<T, void_t<
decltype(std::declval<T&>().foo(size_t{}))
>> : std::true_type {};
int main() {
std::cout << std::boolalpha
<< has_reserve<A>::value << std::endl // true
<< has_reserve<B>::value << std::endl // true
<< has_foo<A>::value << std::endl // false
<< has_foo<B>::value << std::endl // false
;
return 0;
} Can somebody check whether this code works with MSVC? |
@octopus-prime Works fine with MSVC 14.11 (2017 Update 3+). |
It should, because it looks like that one I has |
@Kojoley Really nice job!! Without void_t at all... |
Until we have a good integration for boostorg/spirit in appveyor - this is what we get for now (via private appveyor account):
https://ci.appveyor.com/project/octopus-prime/spirit
The text was updated successfully, but these errors were encountered: