Boost logo

Boost Users :

Subject: Re: [Boost-users] 'Hashable' concept for type erasure
From: Samuel Christie (schrist_at_[hidden])
Date: 2014-03-22 20:13:18

Hmm. Maybe it would be best if I make a custom wrapper class anyway, then.
All I really need is the ability to 1) record 'seen' objects in the
history, and 2) be able to tell whether one of the same objects is in the
history or not. Up until this point, I've been using unordered_sets, but I
was hoping to support more sophisticated memory models that would only
remember recent history, for instance.

Of those choices, I think (b) makes the most sense for my purposes, though
a or c would also be acceptable. I can't really see how I would achieve
that with just type erasure though. This could easily be a case of an
over-used hammer.

If you don't mind my asking, which of them would you recommend, which do
you think is achievable with type-erasure, and what other alternatives do
you think I should be considering?


On Sat, Mar 22, 2014 at 7:48 PM, Steven Watanabe <watanabesj_at_[hidden]>wrote:

> On 03/22/2014 04:10 PM, Samuel Christie wrote:
> > Next problem I'm having though is using it with an erasure that can be
> used
> > to store anything implementing insert and count as in a
> std::unordered_set.
> > I've tried the following simple test, but it seems to have trouble
> > converting between 'int' and the '_value' placeholder type.
> >
> This is a bit tricky. I think, first you need to
> be very clear about exactly what you want.
> When you call history.count(1), the fact that
> history holds an unordered_set<int> has been
> lost. The library has no way to know at compile
> time the value_type is int. So, what do you
> want to happen if I write:
> history.count("a string");
> a) Just don't do that. (i.e. undefined behavior)
> b) return 0; since history obviously doesn't
> contain any strings.
> c) An exception saying that you tried to pass the
> wrong type.
> d) Something else?
> In Christ,
> Steven Watanabe
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at