Comments (9)
Here is the problem:
MSVC unordered containers have a base _Hash
from which reserve
member comes from:
class unordered_map
: public _Hash<_Umap_traits<_Kty, _Ty,
_Uhash_compare<_Kty, _Hasher, _Keyeq>, _Alloc, false>>
but BOOST_TTI_HAS_MEMBER_FUNCTION
cannot introspect for inherited members https://groups.google.com/forum/#!topic/boost-list/awd4kqJezfQ
#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;
}
from spirit.
The errors came from reservable-tests of std::unordered_xyz classes.
So this is the standard
http://en.cppreference.com/w/cpp/container/unordered_map
with reserve()
And this is boost
http://www.boost.org/doc/libs/1_65_1/doc/html/boost/unordered_map.html
with reserve()
But (of course) this is microsoft
https://msdn.microsoft.com/de-de/library/bb982522.aspx
WITHOUT reserve() 👎
from spirit.
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.
from spirit.
Would like to find the difference.
I don't have MSVC - so can not try to find it.
Can only read documentation to find the difference in reserve method.
But documentation says: no reserve method.
https://msdn.microsoft.com/en-us/library/bb982522.aspx
from spirit.
Excellent analysis!
from spirit.
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?
from spirit.
@octopus-prime Works fine with MSVC 14.11 (2017 Update 3+).
from spirit.
It should, because it looks like that one I has
45902cb
from spirit.
@Kojoley Really nice job!! Without void_t at all...
from spirit.
Related Issues (20)
- iso8859_1::isgraph doesn't work correctly
- x3::unicode::format does not recognize certain format control characters HOT 3
- apparent uselessness of as_spirit_parser(...)? HOT 6
- no_case is a type in some make_primitives specializations, and a bool in others. HOT 1
- Boost Spirit X3 Parser recursive HOT 13
- compile error when using error_handler together with x3::variant
- boost::get overloads for boost::spirit::x3::variant should at least lack BOOST_NOEXCEPT
- x3::variant's converting constructor is explicit HOT 1
- `{qi,karma}::symbols` copy constructor does not make an independent copy HOT 2
- x3::double_ failed to parse 1.D-3 HOT 5
- X3 docs for operators is missing syntactical expressions HOT 1
- X3: Incorrect attribute propagation for alternatives with equal attributes HOT 2
- x3::phrase_parse is not expected
- X3: Vector of variant breaks string attributes if variant also contains character type
- X3: expectation operator ">" with semantic rule "[]" expectation_failure<> uses managled name
- mmap_file_iterator uses too restrictive sharing mode in a call to CreateFileA
- Build error C2061: syntax error: identifier 'BOOST_SCOPED_ENUM' on Windows MSVC HOT 1
- need for "RHS" transform_attribute
- boost::get<T>() failed with the x3::forward_ast<> wrapped types HOT 1
- MSVC (VS 2023) fails to compile example/x3/annotation.cpp with /std:c++20 or /std:c++latest option HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spirit.