Is C++ a meme?

Hello,
is there a better way than
namespace std {

template
class hash
{
public:
size_t operator()(const vec2& v) const { return pod_hash(v); }
};

template
class hash
{
public:
size_t operator()(const vec3& v) const { return pod_hash(v); }
};

template
class hash
{ public:
size_t operator()(const vec4& v) const { return pod_hash(v); }
};

or should i try rust?

Attached: c++.png (1600x1600, 25K)

Other urls found in this thread:

doc.rust-lang.org/rust-by-example/trait.html
en.cppreference.com/w/cpp/language/constraints
twitter.com/SFWRedditVideos

yes

thank you, /thread

Rust's trait system would let you have a single Hash where T: vec class

how would rust know which type is trivial_hash_able?

just ruin your codebase
namespace hvec
{
template
class hash
{ public:
size_t operator() (const T& v) const {return pod_hash (v);}
};
}

template
class hash
{
public:
size_t operator()(const T& v) const { return pod_hash(v); }
};


whats the problem user?

just restrict the template to the desired type/types
while we are on it, why isn't you vec type templated? just template that out and specialize on vec and vec.

Learn lisp.

hash

template specializations is better because
i can use it with std::unordered_set without anyone else to write stupid code like.
std::unordered_set

I believe you can reduce it to a single function and just use "if constexpr(...)" with std::is_same to check if it's the type you want.

template
class hash
{
public:
size_t operator()(const T& v) const
{
static_assert( std::is_pod()::value, "use pod idiot");
return pod_hash(v);
}
}:

there we go

so don't do that then

use typetraits with sfinae or constexpr_if u retard

Attached: EBbTlzHWsAE7mh1.jpg (1536x2048, 467K)

make it a trait as he suggested
doc.rust-lang.org/rust-by-example/trait.html

maybe I am missing something can you explain it a little bit more.
puh can i extend std::hash with a template?
as far as i know only template specializations is allowed


i need std::hash cant write my own hash class
because it has to work with std library code.

also i don't want to modify vec type because its also library code. maintaining so much stuff is hard.

Create a HashablePod concept then do with typename replaced with HashablePod
en.cppreference.com/w/cpp/language/constraints

i can't because vec type is not changeable for me.

you can make a hashable trait and implement it for Vec

>concepts
OK, let me just write code from an imaginary compiler that doesn't exist

impl Hashable for Vec {
}

>impl

concepts have been implemented for years in clang and gcc , but the fact is you can very easily emulate them with c++11 type traits

Attached: EBCSuiHUYAAEGet.jpg (1536x2048, 430K)

This isn't a template specialization of std::hash any longer.

don't worry they will make it in c++23

you could use concepts in 2017 if you enabled the flag in gcc lol

but will it compile in 2023?
Thank you

If pod_hash already knows what is a valid template type, why bother trying to implement this hash wrapper?

Make a trait that all of those traits/structs implement and use that instead.

kill yourself

nah

vec can implement a user-made trait

pajeet, my son
you are decent programmer now
must choose between clean, safe, orthogonal Rust traits and the hacky copy of them that isn't even implemented in C++ itself and with which nothing else in C++ works nicely