Boost logo

Boost Users :

Subject: Re: [Boost-users] [mpl] at<> behaves differently for vector_c<> and vector<>
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2017-02-05 20:35:27


AMDG

On 02/05/2017 04:09 AM, ☂Josh Chia (謝任中) wrote:
> I asked earlier in a post "[mpl] Working with map, copy and back_inserter".
>
> This is a related question. The common question is: What does compile-time
> equality means in MPL, particularly for map and set key equality? Does it
> mean std::is_same?

Yes.

> The following code works whether USE_VECTOR_C is defined
> as 0 or 1 -- the last 2 lines are static_asserts that have conditions
> determined by USE_VECTOR_C so that they succeed, highlighting the
> difference in behavior between USE_VECTOR_C == 0 and USE_VECTOR_C == 1.
> USE_VECTOR_C == 0 is the normal case where everything is working as I
> expect. USE_VECTOR_C == 1 is the unexpected case where the static_asserts
> in the last 2 lines have conditions altered so that they succeed.
>
> Why do vector_c and vector give me different "element values"?

  MPL has multiple distinct types that represent
the same integral constant. integral_c<size_t, 0>
is not the same type as size_t<0>, although they're
equivalent in most ways.

> In general,
> what should I be careful about when trying to use the "compile-time values"
> as keys to avoid the situation elucidated by the last line, where I expect
> two "compile-time values" to be the same but they are not, resulting in two
> set/map items instead of one?
>

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net