Giter Site home page Giter Site logo

Comments (9)

Kojoley avatar Kojoley commented on August 18, 2024 1

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.

octopus-prime avatar octopus-prime commented on August 18, 2024

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.

Kojoley avatar Kojoley commented on August 18, 2024

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.

octopus-prime avatar octopus-prime commented on August 18, 2024

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.

octopus-prime avatar octopus-prime commented on August 18, 2024

Excellent analysis!

from spirit.

octopus-prime avatar octopus-prime commented on August 18, 2024

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.

MarcelRaad avatar MarcelRaad commented on August 18, 2024

@octopus-prime Works fine with MSVC 14.11 (2017 Update 3+).

from spirit.

Kojoley avatar Kojoley commented on August 18, 2024

It should, because it looks like that one I has
45902cb

from spirit.

octopus-prime avatar octopus-prime commented on August 18, 2024

@Kojoley Really nice job!! Without void_t at all...

from spirit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.