GithubHelp home page GithubHelp logo

Comments (3)

tudor avatar tudor commented on April 26, 2024

Can you please paste this as text somehow? It seems HTML ate a lot of your
angle brackets :)

Also, what is the error that you're getting? Is it that hashstd::string
is already defined?

On Mon, Jul 7, 2014 at 8:02 PM, likan999 [email protected] wrote:

The following simple program will produce error under libc++:

#include
#include
#include

using namespace std;

namespace std {
template
struct hashstd::basic_string : private hash {
size_t operator()(const std::basic_string & s) const {
return hash::operator()(s.c_str());
}
};
}

const static unordered_map m = {
{"abc", 1},
{"xyz", 2},
};

int main() {
assert(m.find("abc") != m.end());
}

String.h shouldn't specialize hash function for libc++.


Reply to this email directly or view it on GitHub
#74.

from folly.

likan999 avatar likan999 commented on April 26, 2024

@tudor, the specialization is copied from String.h to demonstrate the problem. Simply including "String.h" can also reproduce the same issue. The error is the code successfully compiles under libc++ but at runtime the assertion fails. I guess the culprit is libc++ has a different hash implementation.

I guess the specialization was introduced when c++11 was not yet fully implemented by mainline compilers and hash was not available. But since hash is in C++11 standard, and major compilers supports c++11 faily well, it is no longer needed?

from folly.

tudor avatar tudor commented on April 26, 2024

You're right. Our specialization is actually broken! (because we make
hash call hash<const char*> on s.c_str(), which is clearly bad, as
hash<const char*> doesn't hash the strings, only the pointer value)

We haven't seen this at FB because libstdc++ provides full specializations
(as required by the standard), so hash is more specific than
template hash<basic_string>, so the libstdc++ specialization
wins.

Clearly libc++ does something different (and it's not fully standard
compliant), but, regardless, these specializations are unnecessary AND
broken, so I'll fix.

On Tue, Jul 8, 2014 at 9:51 AM, likan999 [email protected] wrote:

@tudor https://github.com/tudor, the specialization is copied from
String.h to demonstrate the problem. By simply including "String.h" can
also reproduce the same issue. The error is the code successfully compiles
under libc++ but at runtime the assertion fails. I guess the culprit is
libc++ has a different hash implementation.

I guess the specialization was introduced when c++11 was not yet fully
implemented by mainline compilers and hash was not available. But since
hash is in C++11 standard, and major compilers supports c++11 faily well,
it is no longer needed?


Reply to this email directly or view it on GitHub
#74 (comment).

from folly.

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.