1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
|
[/==============================================================================
Copyright (C) 2001-2007 Joel de Guzman, Dan Marsden, Tobias Schwinger
Use, modification and distribution is subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
===============================================================================/]
[section View]
Views are sequences that do not actually contain data, but instead impart
an alternative presentation over the data from one or more underlying
sequences. Views are proxies. They provide an efficient yet purely
functional way to work on potentially expensive sequence operations. Views
are inherently lazy. Their elements are only computed on demand only when
the elements of the underlying sequence(s) are actually accessed. Views'
lazy nature make them very cheap to copy and be passed around by value.
[heading Header]
#include <boost/fusion/view.hpp>
#include <boost/fusion/include/view.hpp>
[section single_view]
`single_view` is a view into a value as a single element sequence.
[heading Header]
#include <boost/fusion/view/single_view.hpp>
#include <boost/fusion/include/single_view.hpp>
[heading Synopsis]
template <typename T>
struct single_view;
[heading Template parameters]
[table
[[Parameter] [Description] [Default]]
[[`T`] [Any type] []]
]
[heading Model of]
* __forward_sequence__
[variablelist Notation
[[`S`] [A `single_view` type]]
[[`s`, `s2`] [Instances of `single_view`]]
[[`x`] [An instance of `T`]]
]
[heading Expression Semantics]
Semantics of an expression is defined only where it differs from, or is not
defined in __forward_sequence__.
[table
[[Expression] [Semantics]]
[[`S(x)`] [Creates a `single_view` from `x`.]]
[[`S(s)`] [Copy constructs a `single_view` from another `single_view`, `s`.]]
[[`s = s2`] [Assigns to a `single_view`, `s`, from another `single_view`, `s2`.]]
]
[heading Example]
single_view<int> view(3);
std::cout << view << std::endl;
[endsect]
[section filter_view]
[heading Description]
`filter_view` is a view into a subset of its underlying sequence's elements
satisfying a given predicate (an __mpl__ metafunction). The `filter_view`
presents only those elements for which its predicate evaluates to
`mpl::true_`.
[heading Header]
#include <boost/fusion/view/filter_view.hpp>
#include <boost/fusion/include/filter_view.hpp>
[heading Synopsis]
template <typename Sequence, typename Pred>
struct filter_view;
[heading Template parameters]
[table
[[Parameter] [Description] [Default]]
[[`Sequence`] [A __forward_sequence__] []]
[[`Pred`] [Unary Metafunction
returning an `mpl::bool_`] []]
]
[heading Model of]
* __forward_sequence__
[variablelist Notation
[[`F`] [A `filter_view` type]]
[[`f`, `f2`] [Instances of `filter_view`]]
[[`s`] [A __forward_sequence__]]
]
[heading Expression Semantics]
Semantics of an expression is defined only where it differs from, or is not
defined in __forward_sequence__.
[table
[[Expression] [Semantics]]
[[`F(s)`] [Creates a `filter_view` given a sequence, `s`.]]
[[`F(f)`] [Copy constructs a `filter_view` from another `filter_view`, `f`.]]
[[`f = f2`] [Assigns to a `filter_view`, `f`, from another `filter_view`, `f2`.]]
]
[heading Example]
using boost::mpl::_;
using boost::mpl::not_;
using boost::is_class;
typedef __vector__<std::string, char, long, bool, double> vector_type;
vector_type v("a-string", '@', 987654, true, 6.6);
filter_view<vector_type const, not_<is_class<_> > > view(v);
std::cout << view << std::endl;
[endsect]
[section iterator_range]
[heading Description]
`iterator_range` presents a sub-range of its underlying sequence delimited
by a pair of iterators.
[heading Header]
#include <boost/fusion/view/iterator_range.hpp>
#include <boost/fusion/include/iterator_range.hpp>
[heading Synopsis]
template <typename First, typename Last>
struct iterator_range;
[heading Template parameters]
[table
[[Parameter] [Description] [Default]]
[[`First`] [A fusion __iterator__] []]
[[`Last`] [A fusion __iterator__] []]
]
[heading Model of]
* __forward_sequence__, __bidirectional_sequence__ or
__random_access_sequence__ depending on the traversal characteristics (see
__traversal_concept__) of its underlying sequence.
[variablelist Notation
[[`IR`] [An `iterator_range` type]]
[[`f`] [An instance of `First`]]
[[`l`] [An instance of `Last`]]
[[`ir`, `ir2`] [Instances of `iterator_range`]]
]
[heading Expression Semantics]
Semantics of an expression is defined only where it differs from, or is not
defined in __forward_sequence__.
[table
[[Expression] [Semantics]]
[[`IR(f, l)`] [Creates an `iterator_range` given iterators, `f` and `l`.]]
[[`IR(ir)`] [Copy constructs an `iterator_range` from another `iterator_range`, `ir`.]]
[[`ir = ir2`] [Assigns to a `iterator_range`, `ir`, from another `iterator_range`, `ir2`.]]
]
[heading Example]
char const* s = "Ruby";
typedef __vector__<int, char, double, char const*> vector_type;
vector_type vec(1, 'x', 3.3, s);
typedef __result_of_begin__<vector_type>::type A;
typedef __result_of_end__<vector_type>::type B;
typedef __result_of_next__<A>::type C;
typedef __result_of_prior__<B>::type D;
C c(vec);
D d(vec);
iterator_range<C, D> range(c, d);
std::cout << range << std::endl;
[endsect]
[section joint_view]
[heading Description]
`joint_view` presents a view which is a concatenation of two sequences.
[heading Header]
#include <boost/fusion/view/joint_view.hpp>
#include <boost/fusion/include/joint_view.hpp>
[heading Synopsis]
template <typename Sequence1, typename Sequence2>
struct joint_view;
[heading Template parameters]
[table
[[Parameter] [Description] [Default]]
[[`Sequence1`] [A __forward_sequence__] []]
[[`Sequence2`] [A __forward_sequence__] []]
]
[heading Model of]
* __forward_sequence__
[variablelist Notation
[[`JV`] [A `joint_view` type]]
[[`s1`] [An instance of `Sequence1`]]
[[`s2`] [An instance of `Sequence2`]]
[[`jv`, `jv2`] [Instances of `joint_view`]]
]
[heading Expression Semantics]
Semantics of an expression is defined only where it differs from, or is not
defined in __forward_sequence__.
[table
[[Expression] [Semantics]]
[[`JV(s1, s2)`] [Creates a `joint_view` given sequences, `s1` and `s2`.]]
[[`JV(jv)`] [Copy constructs a `joint_view` from another `joint_view`, `jv`.]]
[[`jv = jv2`] [Assigns to a `joint_view`, `jv`, from another `joint_view`, `jv2`.]]
]
[heading Example]
__vector__<int, char> v1(3, 'x');
__vector__<std::string, int> v2("hello", 123);
joint_view<
__vector__<int, char>
, __vector__<std::string, int>
> view(v1, v2);
std::cout << view << std::endl;
[endsect]
[section zip_view]
[heading Description]
`zip_view` presents a view which iterates over a collection of __sequence__(s) in parallel. A `zip_view`
is constructed from a __sequence__ of references to the component __sequence__s.
[heading Header]
#include <boost/fusion/view/zip_view.hpp>
#include <boost/fusion/include/zip_view.hpp>
[heading Synopsis]
template <typename Sequences>
struct zip_view;
[heading Template parameters]
[table
[[Parameter] [Description] [Default]]
[[`Sequences`] [A __forward_sequence__ of references to other Fusion __sequence__s] []]
]
[heading Model of]
* __forward_sequence__, __bidirectional_sequence__ or
__random_access_sequence__ depending on the traversal characteristics (see
__traversal_concept__) of its underlying sequence.
[variablelist Notation
[[`ZV`] [A `joint_view` type]]
[[`s`] [An instance of `Sequences`]]
[[`zv1`, `zv2`] [Instances of `ZV`]]
]
[heading Expression Semantics]
Semantics of an expression is defined only where it differs from, or is not
defined in __forward_sequence__.
[table
[[Expression] [Semantics]]
[[`ZV(s)`] [Creates a `zip_view` given a sequence of references to the component __sequence__s.]]
[[`ZV(zv1)`] [Copy constructs a `zip_view` from another `zip_view`, `zv`.]]
[[`zv1 = zv2`] [Assigns to a `zip_view`, `zv`, from another `zip_view`, `zv2`.]]
]
[heading Example]
typedef __vector__<int,int> vec1;
typedef __vector__<char,char> vec2;
vec1 v1(1,2);
vec2 v2('a','b');
typedef __vector__<vec1&, vec2&> sequences;
std::cout << zip_view<sequences>(sequences(v1, v2)) << std::endl; // ((1 a) (2 b))
[endsect]
[section transform_view]
The unary version of `transform_view` presents a view of its underlying
sequence given a unary function object or function pointer. The binary
version of `transform_view` presents a view of 2 underlying sequences,
given a binary function object or function pointer. The `transform_view`
inherits the traversal characteristics (see __traversal_concept__) of
its underlying sequence or sequences.
[heading Header]
#include <boost/fusion/view/transform_view.hpp>
#include <boost/fusion/include/transform_view.hpp>
[heading Synopsis]
[*Unary Version]
template <typename Sequence, typename F1>
struct transform_view;
[*Binary Version]
template <typename Sequence1, typename Sequence2, typename F2>
struct transform_view;
[heading Template parameters]
[table
[[Parameter] [Description] [Default]]
[[`Sequence`] [A __forward_sequence__] []]
[[`Sequence1`] [A __forward_sequence__] []]
[[`Sequence2`] [A __forward_sequence__] []]
[[`F1`] [A unary function object or function pointer. `__boost_result_of_call__<F1(E)>::type` is the return type of an instance of `F1` when called with a value of each element type `E` in the input sequence.] []]
[[`F2`] [A binary function object or function pointer. `__boost_result_of_call__<F2(E1, E2)>::type` is the return type of an instance of `F2` when called with a value of each corresponding pair of element type `E1` and `E2` in the input sequences.] []]
]
[heading Model of]
* __forward_sequence__, __bidirectional_sequence__ or
__random_access_sequence__ depending on the traversal characteristics (see
__traversal_concept__) of its underlying sequence.
[variablelist Notation
[[`TV`] [A `transform_view` type]]
[[`BTV`] [A binary `transform_view` type]]
[[`UTV`] [A unary `transform_view` type]]
[[`f1`] [An instance of `F1`]]
[[`f2`] [An instance of `F2`]]
[[`s`] [An instance of `Sequence`]]
[[`s1`] [An instance of `Sequence1`]]
[[`s2`] [An instance of `Sequence2`]]
[[`tv`, `tv2`] [Instances of `transform_view`]]
]
[heading Expression Semantics]
Semantics of an expression is defined only where it differs from, or is not
defined in __forward_sequence__, __bidirectional_sequence__ or
__random_access_sequence__ depending on the traversal characteristics (see
__traversal_concept__) of its underlying sequence or sequences.
[table
[[Expression] [Semantics]]
[[`UTV(s, f1)`] [Creates a unary `transform_view` given sequence,
`s` and unary function object or function pointer, `f1`.]]
[[`BTV(s1, s2, f2)`] [Creates a binary `transform_view` given sequences, `s1` and `s2`
and binary function object or function pointer, `f2`.]]
[[`TV(tv)`] [Copy constructs a `transform_view` from another `transform_view`, `tv`.]]
[[`tv = tv2`] [Assigns to a `transform_view`, `tv`, from another `transform_view`, `tv2`.]]
]
[heading Example]
struct square
{
template<typename Sig>
struct result;
template<typename U>
struct result<square(U)>
: remove_reference<U>
{};
template <typename T>
T operator()(T x) const
{
return x * x;
}
};
typedef __vector__<int, short, double> vector_type;
vector_type vec(2, 5, 3.3);
transform_view<vector_type, square> transform(vec, square());
std::cout << transform << std::endl;
[endsect]
[section reverse_view]
`reverse_view` presents a reversed view of underlying sequence. The first
element will be its last and the last element will be its first.
[heading Header]
#include <boost/fusion/view/reverse_view.hpp>
#include <boost/fusion/include/reverse_view.hpp>
[heading Synopsis]
template <typename Sequence>
struct reverse_view;
[heading Template parameters]
[table
[[Parameter] [Description] [Default]]
[[`Sequence`] [A __bidirectional_sequence__] []]
]
[heading Model of]
* __bidirectional_sequence__
[variablelist Notation
[[`RV`] [A `reverse_view` type]]
[[`s`] [An instance of `Sequence`]]
[[`rv`, `rv2`] [Instances of `reverse_view`]]
]
[heading Expression Semantics]
Semantics of an expression is defined only where it differs from, or is not
defined in __bidirectional_sequence__.
[table
[[Expression] [Semantics]]
[[`RV(s)`] [Creates a unary `reverse_view` given sequence, `s`.]]
[[`RV(rv)`] [Copy constructs a `reverse_view` from another `reverse_view`, `rv`.]]
[[`rv = rv2`] [Assigns to a `reverse_view`, `rv`, from another `reverse_view`, `rv2`.]]
]
[heading Example]
typedef __vector__<int, short, double> vector_type;
vector_type vec(2, 5, 3.3);
reverse_view<vector_type> reverse(vec);
std::cout << reverse << std::endl;
[endsect]
[endsect]
|