Boost logo

Boost :

Subject: Re: [boost] [mpl] multiset
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2015-02-26 10:28:24


AMDG

On 02/26/2015 05:25 AM, Ganesh Prasad wrote:
> <snip>
> After all TMP is turing complete, hence,
> random access containers should not be non-existent.
>

Turing completeness does not guarantee the
existence of random access. Complexity
classes (i.e. L, P, NP) are invariant
across computation models, but random access
is not a distinct complexity class.

With that being said, mpl emulates random
access like this:

template<class Base, int N, class T>
struct v_item;

template<class Base, class T>
struct v_item<Vector, 0, T> : Base { typedef T item0; };
template<class Base, class T>
struct v_item<Vector, 1, T> : Base { typedef T item1; };
...

This can also be acheived using overload resolution
and decltype:
template<class Base, int N, class T>
struct v_item : Base {
  using Base::item;
  wrap<T> item(int_<N>);
};

This isn't actually constant time, however, because
of the way most compilers implement overload resolution.

In Christ,
Steven Watanabe


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk