Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-08-22 13:51:04


"Alex Chovanec" <achovane_at_[hidden]> wrote in message
news:cganiq$q27$1_at_sea.gmane.org...
>
> "Jonathan Turkanis" <technews_at_[hidden]> wrote in message
> news:cgal34$l63$1_at_sea.gmane.org...
>
> > Currently there is detail::is_incrementable, which works well if
you
> > only need to distinguish between iterators and very different
types.
> > For instance, I would guess that very few if any containers are
> > incrementable (I'd be happy to be proved wrong here), so that if
you
> > want define a function which behaves differently for container and
> > iterators you can use is_incrementable.
>
> In this case, I need to know whether or not type T is
dereferenceable

I've attached a naively modified version of David Abraham's
is_incrementable as a first attempt at is_dereferenceable. There may
be all sorts of subtle issues I haven't though of.

> (and
> more generally, whether or not it's an iterator).

Why? When you write a template, you always have some idea of the range
of types for which the template should be instantiated. It's rarely
instantiable for all types. Given this, all you need is a way to
separate iterators from the other candidate template arguments.

> I have a small template
> metaprogram which determines how an instance of type T should be
treated. If
> it's an iterator, I want to dereference it. Otherwise, I don't.
>
> > Don't forget pointers. Also these operators can also be defined as
> > non-member functions.
>
> Pointers are fairly easy to handle.

True.

> You bring up an important point about operators defined as
non-member
> functions. My current implementation doesn't handle this case, but I
may yet
> be able to fix that. :-)

Try the attachment.

> Thanks for the feedback,
>
> Alex

begin 666 is_dereferenceable.hpp
M+R\@3F%I=F5L>2!M;V1I9FEE9"!V97)S:6]N(&]F(&)O;W-T+V1E=&%I;"]I
M<U]I;F-R96UE;G1A8FQE+FAP<"P_at_87,@9FER<W0@#0HO+R!A='1E;7!T(&%T
M(&ES7V1E<F5F97)E;F-E86)L92P_at_8GD@2F]N871H86X_at_5'5R:V%N:7,N#0H-
M"B\O($-O<'ER:6=H="!$879I9"!!8G)A:&%M<R R,# T+B!5<V4L(&UO9&EF
M:6-A=&EO;B!A;F0_at_9&ES=')I8G5T:6]N(&ES#0HO+R!S=6)J96-T('1O('1H
M92!";V]S="!3;V9T=V%R92!,:6-E;G-E+"!697)S:6]N(#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M92!R96UO=F5?8W8\5#XZ.G1Y<&4F('@[#0H-"B @(" @($)/
M3U-47U-4051)0U]#3TY35$%.5"@-"B @(" @(" @("!B;V]L#0H@(" @(" @
M("P@=F%L=64@/2!S:7IE;V8H:7-?9&5R969E<F5N8V5A8FQE7SHZ8VAE8VLH
M0D]/4U1?8V]M;6$H*G_at_L,"DI*2 ]/2 Q#0H@(" @(" I.PT*("!].PT*?0T*
M#0HC('5N9&5F($)/3U-47V-O;6UA#0H-"G1E;7!L871E(#QC;&%S<R!4/@T*
M<W1R=6-T(&ES7V1E<F5F97)E;F-E86)L90T*(" Z(&UP;#HZ8F]O;%\\(#HZ
M8F]O<W0Z.F1E=&%I;#HZ:7-?9&5R969E<F5N8V5A8FQE7SHZ:6UP;#Q4/CHZ
M=F%L=64^#0I[#0I].PT*#0I]?2 O+R!N86UE<W!A8V4_at_8F]O<W0Z.F1E=&%I
M; T*#0HC96YD:68@+R\@25-?1$52149%4D5.0T5!0DQ%7TA04%])3D-,541%
#1 T*
`
end


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