|
Boost Users : |
Subject: Re: [Boost-users] [range] contiguous iterators
From: Kyle Lutz (kyle.r.lutz_at_[hidden])
Date: 2013-03-18 20:08:37
On Sat, Mar 16, 2013 at 10:42 AM, Stefan Strasser
<strasser_at_[hidden]> wrote:
> Hi everyone,
>
> is there any way to generically determine at compiletime whether an iterator
> or a boost range refers to contiguous memory?
>
> i.e. &*(it+1) == (&*it)+1
>
> some type trait like
>
> is_contiguous<T *>::value == true
> is_contiguous<vector<T>::iterator>::value == true
> is_contiguous<std::list<T>::iterator>::value == false
>
> ?
Hi Stefan,
I needed this functionality for Boost.Compute in order to determine if
a region of memory could be copied directly to the GPU or if an
intermediate std::vector was required. It works just like your example
except I used the name is_contiguous_iterator instead.
The implementation is here:
https://github.com/kylelutz/compute/blob/master/include/boost/compute/detail/is_contiguous_iterator.hpp
Cheers,
Kyle
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