hosseinmoein / DataFrame

C++ DataFrame for statistical, Financial, and ML analysis -- in modern C++ using native types and contiguous memory storage
https://hosseinmoein.github.io/DataFrame/
BSD 3-Clause "New" or "Revised" License
2.52k stars 314 forks source link

[help] std::hash redefine error #114

Closed westfly closed 3 years ago

westfly commented 3 years ago

I'm Using DataFrame (version 1.17.0) as a library in a Project with many other libs, when compile code I got Error message as below

DataFrame/Internals/DataFrame_standalone.tcc:1082:9: error: redefinition of 'struct std::hash<std::tuple<_Tps ...> >'
 struct  hash<std::tuple<TT ...>>  {
         ^~~~~~~~~~~~~~~~~~~~~~~~
tuple_helper.h:100:8: note: previous definition of 'struct std::hash<std::tuple<_Tps ...> >'
 struct hash<std::tuple<TT...>>

as post Hashing a tuple in C++17 describe

However, I was viewing this as more of a hash library than extensions to std

so This may case by redefine std::hash in DataFrame_standalone

namespace std  {
template<typename ... TT>
struct  hash<std::tuple<TT ...>>  {
    inline size_t operator()(std::tuple<TT ...> const &in_tuple) const  {
        size_t  seed = 0;
        hmdf::_hash_value_impl_<std::tuple<TT ...>>::apply(seed, in_tuple);
        return (seed);
    }
};

Is there an solution to avoid this ?

hosseinmoein commented 3 years ago

I cannot reproduce this on my side and I haven't seen this in any of the compiling environments. So, I have a few questions:

How do you compile this? Are you following the CMake instructions in README? What compiler do you use and in what OS? Have you made any modifications to the source code?

westfly commented 3 years ago

I cannot reproduce this on my side and I haven't seen this in any of the compiling environments. So, I have a few questions:

How do you compile this? Are you following the CMake instructions in README? What compiler do you use and in what OS? Have you made any modifications to the source code?

add more detail to main post

  1. compile with other libs
  2. compiler gcc 7.3 on centos7
  3. no
hosseinmoein commented 3 years ago

I believe this is happening for you because you are also using Boost. This is also defined in Boost library. Can you please verify that?

There are two solutions to that:

  1. Guard my definition by #ifndef BOOST_VERSION
  2. Use boost by prepending boost:: namespace to it calls.

I will add a guard to my definition. But before that, can you verify that my diagnosis are correct?

hosseinmoein commented 3 years ago

I had a better solution. In master, I replaced specialization of std::hash for tuples with TupleHash. Please try master and let me know.

This works for the usage I have in DataFrame library. But it is not a general solution for tuples

westfly commented 3 years ago

OK,It Works. Thx for your great work.