Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/concept_check/stl_concept_covering.cpp @ 47

Last change on this file since 47 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 29.7 KB
Line 
1// (C) Copyright Jeremy Siek 2000-2002.
2// Distributed under the Boost Software License, Version 1.0. (See
3// accompanying file LICENSE_1_0.txt or copy at
4// http://www.boost.org/LICENSE_1_0.txt)
5
6#include <algorithm>
7#include <numeric>
8#include <boost/config.hpp>
9#include <boost/concept_check.hpp>
10#include <boost/concept_archetype.hpp>
11
12/*
13
14 This file uses the archetype classes to find out which concepts
15 actually *cover* the STL algorithms true requirements. The
16 archetypes/concepts chosen do not necessarily match the C++ standard
17 or the SGI STL documentation, but instead were chosen based on the
18 minimal concepts that current STL implementations require, which in
19 many cases is less stringent than the standard. In some places there
20 was significant differences in the implementations' requirements and
21 in those places macros were used to select different requirements,
22 the purpose being to document what the requirements of various
23 implementations are.  It is an open issue as to whether the C++
24 standard should be changed to reflect these weaker requirements.
25
26*/
27
28boost::detail::dummy_constructor dummy_cons;
29
30// This is a special concept needed for std::swap_ranges.
31// It is mutually convertible, and also SGIAssignable
32template <class T>
33class mutually_convertible_archetype
34{
35private:
36  mutually_convertible_archetype() { }
37public:
38  mutually_convertible_archetype(const mutually_convertible_archetype&) { }
39  mutually_convertible_archetype& 
40  operator=(const mutually_convertible_archetype&)
41    { return *this; }
42  mutually_convertible_archetype(boost::detail::dummy_constructor) { }
43
44  template <class U>
45  mutually_convertible_archetype& 
46  operator=(const mutually_convertible_archetype<U>&)
47    { return *this; }
48
49};
50
51
52// for std::accumulate
53namespace accum
54{
55  typedef boost::sgi_assignable_archetype<> Ret;
56  struct T {
57    T(const Ret&) { }
58    T(boost::detail::dummy_constructor x) { }
59  };
60  typedef boost::null_archetype<> Tin;
61  Ret operator+(const T&, const Tin&) {
62    return Ret(dummy_cons);
63  }
64}
65
66// for std::inner_product
67namespace inner_prod
68{
69  typedef boost::sgi_assignable_archetype<> RetAdd;
70  typedef boost::sgi_assignable_archetype<> RetMult;
71  struct T {
72    T(const RetAdd&) { }
73    T(boost::detail::dummy_constructor x) { }
74  };
75  typedef boost::null_archetype<int> Tin1;
76  typedef boost::null_archetype<char> Tin2;
77}
78
79namespace boost { // so Koenig lookup will find
80
81  inner_prod::RetMult
82  operator*(const inner_prod::Tin1&, const inner_prod::Tin2&) {
83    return inner_prod::RetMult(dummy_cons);
84  }
85  inner_prod::RetAdd
86  operator+(const inner_prod::T&, 
87            const inner_prod::RetMult&) {
88    return inner_prod::RetAdd(dummy_cons);
89  }
90}
91
92
93// for std::partial_sum and adj_diff
94namespace part_sum
95{
96  class T {
97  public:
98    typedef boost::sgi_assignable_archetype<> Ret;
99    T(const Ret&) { }
100    T(boost::detail::dummy_constructor x) { } 
101  private:
102    T() { }
103  };
104  T::Ret operator+(const T&, const T&) {
105    return T::Ret(dummy_cons);
106  }
107  T::Ret operator-(const T&, const T&) {
108    return T::Ret(dummy_cons);
109  }
110}
111
112// for std::power
113
114namespace power_stuff {
115  struct monoid_archetype {
116    monoid_archetype(boost::detail::dummy_constructor x) { } 
117  };
118 
119  boost::multipliable_archetype<monoid_archetype>
120  identity_element
121  (std::multiplies< boost::multipliable_archetype<monoid_archetype> >) 
122  {
123    return boost::multipliable_archetype<monoid_archetype>(dummy_cons);
124  }
125}
126
127struct tag1 { };
128struct tag2 { };
129
130
131int
132main()
133{
134  using namespace boost;
135
136  //===========================================================================
137  // Non-mutating Algorithms
138  {
139    input_iterator_archetype< null_archetype<> > in;
140    unary_function_archetype< null_archetype<> , null_archetype<> > 
141      f(dummy_cons);
142    std::for_each(in, in, f);
143  }
144  // gcc bug
145  {
146    typedef equality_comparable2_first_archetype<> Left;
147    input_iterator_archetype< Left > in;
148    equality_comparable2_second_archetype<> value(dummy_cons);
149    in = std::find(in, in, value);
150  }
151  {
152    typedef null_archetype<> T;
153    input_iterator_archetype<T> in;
154    unary_predicate_archetype<T> pred(dummy_cons);
155    in = std::find_if(in, in, pred);
156  }
157  {
158    forward_iterator_archetype< equality_comparable_archetype<> > fo;
159    fo = std::adjacent_find(fo, fo);
160  }
161  {
162    forward_iterator_archetype< 
163      convertible_to_archetype< null_archetype<>  > > fo;
164    binary_predicate_archetype<null_archetype<> , null_archetype<> > 
165      pred(dummy_cons);
166    fo = std::adjacent_find(fo, fo, pred);
167  }
168  // gcc bug
169  {
170    typedef equal_op_first_archetype<> Left;
171    input_iterator_archetype<Left> in;
172    typedef equal_op_second_archetype<> Right;
173    forward_iterator_archetype<Right> fo;
174    in = std::find_first_of(in, in, fo, fo);
175  }
176  {
177    typedef equal_op_first_archetype<> Left;
178    typedef input_iterator_archetype<Left> InIter;
179    InIter in;
180    function_requires< InputIteratorConcept<InIter> >();
181    equal_op_second_archetype<> value(dummy_cons);
182    std::iterator_traits<InIter>::difference_type
183      n = std::count(in, in, value);
184    ignore_unused_variable_warning(n);
185  }
186  {
187    typedef input_iterator_archetype< null_archetype<> > InIter;
188    InIter in;
189    unary_predicate_archetype<null_archetype<> > pred(dummy_cons);
190    std::iterator_traits<InIter>::difference_type
191      n = std::count_if(in, in, pred);
192    ignore_unused_variable_warning(n);
193  }
194  // gcc bug
195  {
196    typedef equal_op_first_archetype<> Left;
197    typedef input_iterator_archetype<Left> InIter1;
198    InIter1 in1;
199    typedef equal_op_second_archetype<> Right;
200    typedef input_iterator_archetype<Right> InIter2;
201    InIter2 in2;
202    std::pair<InIter1, InIter2> p = std::mismatch(in1, in1, in2);
203    ignore_unused_variable_warning(p);
204  }
205  {
206    typedef input_iterator_archetype<null_archetype<> > InIter;
207    InIter in1, in2;
208    binary_predicate_archetype<null_archetype<> , null_archetype<> > 
209      pred(dummy_cons);
210    std::pair<InIter, InIter> p = std::mismatch(in1, in1, in2, pred);
211    ignore_unused_variable_warning(p);
212  }
213  // gcc bug
214  {
215    typedef equality_comparable2_first_archetype<> Left;
216    input_iterator_archetype<Left> in1;
217    typedef equality_comparable2_second_archetype<> Right;
218    input_iterator_archetype<Right> in2;
219    bool b = std::equal(in1, in1, in2);
220    ignore_unused_variable_warning(b);
221  }
222  {
223    input_iterator_archetype< null_archetype<> >
224      in1, in2;
225    binary_predicate_archetype<null_archetype<> , null_archetype<> > 
226      pred(dummy_cons);
227    bool b = std::equal(in1, in1, in2, pred);
228    ignore_unused_variable_warning(b);
229  }
230  {
231    typedef equality_comparable2_first_archetype<> Left;
232    forward_iterator_archetype<Left> fo1;
233    typedef equality_comparable2_second_archetype<> Right;
234    forward_iterator_archetype<Right> fo2;
235    fo1 = std::search(fo1, fo1, fo2, fo2);
236  }
237  {
238    typedef equality_comparable2_first_archetype< 
239      convertible_to_archetype<null_archetype<> > > Left;
240    forward_iterator_archetype<Left> fo1;
241    typedef equality_comparable2_second_archetype<
242      convertible_to_archetype<null_archetype<> > > Right;
243    forward_iterator_archetype<Right> fo2;
244    binary_predicate_archetype<null_archetype<> , null_archetype<> > 
245      pred(dummy_cons);
246    fo1 = std::search(fo1, fo1, fo2, fo2, pred);
247  }
248  {
249    typedef equality_comparable2_first_archetype<> Left;
250    forward_iterator_archetype<Left> fo;
251    equality_comparable2_second_archetype<> value(dummy_cons);
252    int n = 1;
253    fo = std::search_n(fo, fo, n, value);
254  }
255  {
256    forward_iterator_archetype< 
257      convertible_to_archetype<null_archetype<> > > fo;
258    convertible_to_archetype<null_archetype<> > value(dummy_cons);
259    binary_predicate_archetype<null_archetype<> , null_archetype<> > 
260      pred(dummy_cons);
261    int n = 1;
262    fo = std::search_n(fo, fo, n, value, pred);
263  }
264  {
265    typedef equality_comparable2_first_archetype<> Left;
266    forward_iterator_archetype<Left> fo1;
267    typedef equality_comparable2_second_archetype<null_archetype<> > Right;
268    forward_iterator_archetype<Right> fo2;
269    fo1 = std::find_end(fo1, fo1, fo2, fo2);
270  }
271  {
272    // equality comparable required because find_end() calls search
273    typedef equality_comparable2_first_archetype<
274      convertible_to_archetype<null_archetype<> > > Left;
275    forward_iterator_archetype<Left> fo1;
276    typedef equality_comparable2_second_archetype<
277      convertible_to_archetype<null_archetype<> > > Right;
278    forward_iterator_archetype<Right> fo2;
279    binary_predicate_archetype<null_archetype<> , null_archetype<> > 
280      pred(dummy_cons);
281    fo1 = std::find_end(fo1, fo1, fo2, fo2, pred);
282  }
283
284  //===========================================================================
285  // Mutating Algorithms
286
287  {
288    typedef null_archetype<> T;
289    input_iterator_archetype<T> in;
290    output_iterator_archetype<T> out(dummy_cons);
291    out = std::copy(in, in, out);
292  }
293  {
294    typedef assignable_archetype<> OutT;
295    typedef convertible_to_archetype<OutT> InT;
296    bidirectional_iterator_archetype<InT> bid_in;
297    mutable_bidirectional_iterator_archetype<OutT> bid_out;
298    bid_out = std::copy_backward(bid_in, bid_in, bid_out);
299  }
300  {
301    sgi_assignable_archetype<> a(dummy_cons), b(dummy_cons);
302    std::swap(a, b);
303  }
304  {
305    typedef sgi_assignable_archetype<> T;
306    mutable_forward_iterator_archetype<T> a, b;
307    std::iter_swap(a, b);
308  }
309  {
310    typedef mutually_convertible_archetype<int> Tin;
311    typedef mutually_convertible_archetype<char> Tout;
312    mutable_forward_iterator_archetype<Tin> fi1;
313    mutable_forward_iterator_archetype<Tout> fi2;
314    fi2 = std::swap_ranges(fi1, fi1, fi2);
315  }
316  {
317    typedef null_archetype<int> Tin;
318    typedef null_archetype<char> Tout;
319    input_iterator_archetype<Tin> in;
320    output_iterator_archetype<Tout> out(dummy_cons);
321    unary_function_archetype<null_archetype<> , 
322      convertible_to_archetype<Tout> > op(dummy_cons);
323    out = std::transform(in, in, out, op);
324  }
325  {
326    typedef null_archetype<int> Tin1;
327    typedef null_archetype<char> Tin2;
328    typedef null_archetype<double> Tout;
329    input_iterator_archetype<Tin1> in1;
330    input_iterator_archetype<Tin2> in2;
331    output_iterator_archetype<Tout> out(dummy_cons);
332    binary_function_archetype<Tin1, Tin2,
333      convertible_to_archetype<Tout> > op(dummy_cons);
334    out = std::transform(in1, in1, in2, out, op);
335  }
336  {
337    typedef equality_comparable2_first_archetype<
338      assignable_archetype<> > FT;
339    mutable_forward_iterator_archetype<FT> fi;
340    equality_comparable2_second_archetype<
341      convertible_to_archetype<FT> > value(dummy_cons);
342    std::replace(fi, fi, value, value);
343  }
344  {
345    typedef null_archetype<> PredArg;
346    typedef assignable_archetype< 
347      convertible_to_archetype<PredArg> > FT;
348    mutable_forward_iterator_archetype<FT> fi;
349    unary_predicate_archetype<PredArg> pred(dummy_cons);
350    convertible_to_archetype<FT> value(dummy_cons);
351    std::replace_if(fi, fi, pred, value);
352  }
353  // gcc bug
354  {
355    // Issue, the use of ?: inside replace_copy() complicates things
356    typedef equal_op_first_archetype<> Tin;
357    typedef null_archetype<> Tout;
358    typedef equal_op_second_archetype< convertible_to_archetype<Tout> > T;
359    input_iterator_archetype<Tin> in;
360    output_iterator_archetype<Tout> out(dummy_cons);
361    T value(dummy_cons);
362    out = std::replace_copy(in, in, out, value, value);
363  }
364  {
365    // The issue of ?: also affects this function
366    typedef null_archetype<> Tout;
367    typedef assignable_archetype< convertible_to_archetype<Tout> > Tin;
368    input_iterator_archetype<Tin> in;
369    output_iterator_archetype<Tout> out(dummy_cons);
370    unary_predicate_archetype<Tin> pred(dummy_cons);
371    Tin value(dummy_cons);
372    out = std::replace_copy_if(in, in, out, pred, value);
373  }
374  {
375    typedef assignable_archetype<> FT;
376    mutable_forward_iterator_archetype<FT> fi;
377    typedef convertible_to_archetype<FT> T;
378    T value(dummy_cons);
379    std::fill(fi, fi, value);
380  } 
381  {
382    typedef null_archetype<> Tout;
383    typedef convertible_to_archetype<Tout> T;
384    output_iterator_archetype<Tout> out(dummy_cons);
385    T value(dummy_cons);
386    int n = 1;
387    out = std::fill_n(out, n, value);
388  }
389  {
390    typedef assignable_archetype<> FT;
391    typedef convertible_to_archetype<FT> Ret;
392    mutable_forward_iterator_archetype<FT> fi;
393    generator_archetype<Ret> gen;
394    std::generate(fi, fi, gen);
395  }
396  {
397    typedef assignable_archetype<> FT;
398    typedef convertible_to_archetype<FT> Ret;
399    mutable_forward_iterator_archetype<FT> fi;
400    generator_archetype<Ret> gen;
401    int n = 1;
402    std::generate_n(fi, n, gen);
403  }
404  {
405    typedef assignable_archetype< equality_comparable2_first_archetype<> > FT;
406    typedef equality_comparable2_second_archetype<> T;
407    mutable_forward_iterator_archetype<FT> fi;
408    T value(dummy_cons);
409    fi = std::remove(fi, fi, value);
410  }
411  {
412    typedef assignable_archetype<> FT;
413    mutable_forward_iterator_archetype<FT> fi;
414    typedef null_archetype<> PredArg;
415    unary_predicate_archetype<PredArg> pred(dummy_cons);
416    fi = std::remove_if(fi, fi, pred);
417  }
418  // gcc bug
419  {
420    typedef null_archetype<> Tout;
421    typedef equality_comparable2_first_archetype<
422      convertible_to_archetype<Tout> > Tin;
423    typedef equality_comparable2_second_archetype<> T;
424    input_iterator_archetype<Tin> in;
425    output_iterator_archetype<Tout> out(dummy_cons);
426    T value(dummy_cons);
427    out = std::remove_copy(in, in, out, value);
428  }
429  {
430    typedef null_archetype<> T;
431    input_iterator_archetype<T> in;
432    output_iterator_archetype<T> out(dummy_cons);
433    unary_predicate_archetype<T> pred(dummy_cons);
434    out = std::remove_copy_if(in, in, out, pred);
435  }
436  {
437    typedef sgi_assignable_archetype< equality_comparable_archetype<> > T;
438    mutable_forward_iterator_archetype<T> fi;
439    fi = std::unique(fi, fi);
440  }
441  {
442    typedef null_archetype<int> Arg1;
443    typedef null_archetype<char> Arg2;
444    typedef sgi_assignable_archetype< 
445      convertible_to_archetype<Arg1,
446      convertible_to_archetype<Arg2> > > FT;
447    mutable_forward_iterator_archetype<FT> fi;
448    binary_predicate_archetype<Arg1, Arg2> pred(dummy_cons);
449    fi = std::unique(fi, fi, pred);
450  }
451  // gcc bug
452  {
453    typedef equality_comparable_archetype< sgi_assignable_archetype<> > T;
454    input_iterator_archetype<T> in;
455    output_iterator_archetype<T> out(dummy_cons);
456    out = std::unique_copy(in, in, out);
457  }
458  {
459    typedef sgi_assignable_archetype<> T;
460    input_iterator_archetype<T> in;
461    output_iterator_archetype<T> out(dummy_cons);
462    binary_predicate_archetype<T, T> pred(dummy_cons);
463    out = std::unique_copy(in, in, out, pred);
464  }
465  {
466    typedef sgi_assignable_archetype<> T;
467    mutable_bidirectional_iterator_archetype<T> bi;
468    std::reverse(bi, bi);
469  }
470  {
471    typedef null_archetype<> Tout;
472    typedef convertible_to_archetype<Tout> Tin;
473    bidirectional_iterator_archetype<Tin> bi;
474    output_iterator_archetype<Tout> out(dummy_cons);
475    out = std::reverse_copy(bi, bi, out);
476  }
477  {
478    typedef sgi_assignable_archetype<> T;
479    mutable_forward_iterator_archetype<T> fi;
480    // Issue, SGI STL is not have void return type, C++ standard does
481    std::rotate(fi, fi, fi);
482  }
483  {
484    typedef null_archetype<> Tout;
485    typedef convertible_to_archetype<Tout> FT;
486    forward_iterator_archetype<FT> fi;
487    output_iterator_archetype<Tout> out(dummy_cons);
488    out = std::rotate_copy(fi, fi, fi, out);
489  }
490  {
491    typedef sgi_assignable_archetype<> T;
492    mutable_random_access_iterator_archetype<T> ri;
493    std::random_shuffle(ri, ri);
494  }
495  {
496    typedef sgi_assignable_archetype<> T;
497    mutable_random_access_iterator_archetype<T> ri;
498    unary_function_archetype<std::ptrdiff_t, std::ptrdiff_t> ran(dummy_cons);
499    std::random_shuffle(ri, ri, ran);
500  }
501  {
502    typedef null_archetype<> PredArg;
503    typedef sgi_assignable_archetype<convertible_to_archetype<PredArg> > FT;
504    mutable_bidirectional_iterator_archetype<FT> bi;
505    unary_predicate_archetype<PredArg> pred(dummy_cons);
506    bi = std::partition(bi, bi, pred);
507  }
508  {
509    typedef null_archetype<> PredArg;
510    typedef sgi_assignable_archetype<convertible_to_archetype<PredArg> > FT;
511    mutable_forward_iterator_archetype<FT> fi;
512    unary_predicate_archetype<PredArg> pred(dummy_cons);
513    fi = std::stable_partition(fi, fi, pred);
514  }
515
516  //===========================================================================
517  // Sorting Algorithms
518  {
519    typedef sgi_assignable_archetype< 
520      less_than_comparable_archetype<> > T;
521    mutable_random_access_iterator_archetype<T> ri;
522    std::sort(ri, ri);
523  }
524  {
525    typedef null_archetype<> Arg;
526    typedef sgi_assignable_archetype< 
527      convertible_to_archetype<Arg> > T;
528    mutable_random_access_iterator_archetype<T> ri;
529    binary_predicate_archetype<Arg, Arg> comp(dummy_cons);
530    std::sort(ri, ri, comp);
531  }
532  {
533    typedef less_than_comparable_archetype< 
534        sgi_assignable_archetype<> > ValueType;
535    mutable_random_access_iterator_archetype<ValueType> ri;
536    std::stable_sort(ri, ri);
537  }
538  {
539    typedef null_archetype<> Arg;
540    typedef sgi_assignable_archetype<
541      convertible_to_archetype<Arg> > ValueType;
542    mutable_random_access_iterator_archetype<ValueType> ri;
543    binary_predicate_archetype<Arg, Arg> comp(dummy_cons);
544    std::stable_sort(ri, ri, comp);
545  }
546  {
547    typedef sgi_assignable_archetype< 
548      less_than_comparable_archetype<> > T;
549    mutable_random_access_iterator_archetype<T> ri;
550    std::partial_sort(ri, ri, ri);
551  }
552
553  {
554    typedef null_archetype<> Arg;
555    typedef sgi_assignable_archetype< 
556      convertible_to_archetype<Arg> > T;
557    mutable_random_access_iterator_archetype<T> ri;
558    binary_predicate_archetype<Arg, Arg> comp(dummy_cons);
559    std::partial_sort(ri, ri, ri, comp);
560  }
561  // gcc bug
562  {
563    // This could be formulated so that the two iterators are not
564    // required to have the same value type, but it is messy.
565    typedef sgi_assignable_archetype< 
566      less_than_comparable_archetype<> > T;
567    input_iterator_archetype<T> in;
568    mutable_random_access_iterator_archetype<T> ri_out;
569    ri_out = std::partial_sort_copy(in, in , ri_out, ri_out);
570  }
571  {
572    typedef sgi_assignable_archetype<> T;
573    input_iterator_archetype<T> in;
574    mutable_random_access_iterator_archetype<T> ri_out;
575    binary_predicate_archetype<T, T> comp(dummy_cons);
576    ri_out = std::partial_sort_copy(in, in , ri_out, ri_out, comp);
577  }
578  {
579    typedef sgi_assignable_archetype< less_than_comparable_archetype<> > T;
580    mutable_random_access_iterator_archetype<T> ri;
581    std::nth_element(ri, ri, ri);
582  }
583  {
584    typedef null_archetype<int> Arg1;
585    typedef null_archetype<char> Arg2;
586    typedef sgi_assignable_archetype<
587      convertible_to_archetype<Arg1,
588      convertible_to_archetype<Arg2> > > T;
589    mutable_random_access_iterator_archetype<T> ri;
590    binary_predicate_archetype<Arg1, Arg2> comp(dummy_cons);
591    std::nth_element(ri, ri, ri, comp);
592  }
593  {
594#if defined(__GNUC__) || defined(__IBMCPP__)
595    typedef less_than_op_first_archetype<> FT;
596    typedef less_than_op_second_archetype<> T;
597#elif defined(__KCC)
598    // The KAI version of this uses a one-argument less-than function
599    // object.
600    typedef less_than_comparable_archetype<> T;
601    typedef convertible_to_archetype<T> FT;
602#endif
603    forward_iterator_archetype<FT> fi;
604    T value(dummy_cons);
605    fi = std::lower_bound(fi, fi, value);
606  }
607  {
608    typedef null_archetype<int> Arg1;
609    typedef null_archetype<char> Arg2;
610    typedef convertible_to_archetype<Arg1> FT;
611    typedef convertible_to_archetype<Arg2> T;
612    forward_iterator_archetype<FT> fi;
613    T value(dummy_cons);
614    binary_predicate_archetype<Arg1, Arg2> comp(dummy_cons);
615    fi = std::lower_bound(fi, fi, value, comp);
616  }
617  {
618#if defined(__GNUC__)  || defined(__IBMCPP__)
619    // Note, order of T,FT is flipped from lower_bound
620    typedef less_than_op_second_archetype<> FT;
621    typedef less_than_op_first_archetype<> T;
622#elif defined(__KCC)
623    typedef less_than_comparable_archetype<> T;
624    typedef convertible_to_archetype<T> FT;
625#endif
626    forward_iterator_archetype<FT> fi;
627    T value(dummy_cons);
628    fi = std::upper_bound(fi, fi, value);
629  }
630  {
631    typedef null_archetype<int> Arg1;
632    typedef null_archetype<char> Arg2;
633    // Note, order of T,FT is flipped from lower_bound
634    typedef convertible_to_archetype<Arg1> T;
635    typedef convertible_to_archetype<Arg2> FT;
636    forward_iterator_archetype<FT> fi;
637    T value(dummy_cons);
638    binary_predicate_archetype<Arg1, Arg2> comp(dummy_cons);
639    fi = std::upper_bound(fi, fi, value, comp);
640  }
641  {
642#if defined(__GNUC__) || defined(__IBMCPP__)
643    typedef less_than_op_first_archetype<
644      less_than_op_second_archetype< null_archetype<>, optag2>, optag1> FT;
645    typedef less_than_op_second_archetype<
646      less_than_op_first_archetype< null_archetype<>, optag2>, optag1> T;
647#elif defined(__KCC)
648    typedef less_than_comparable_archetype<> T;
649    typedef convertible_to_archetype<T> FT;
650#endif
651    typedef forward_iterator_archetype<FT> FIter;
652    FIter fi;
653    T value(dummy_cons);
654    std::pair<FIter,FIter> p = std::equal_range(fi, fi, value);
655    ignore_unused_variable_warning(p);
656  }
657  {
658    typedef null_archetype<int> Arg1;
659    typedef null_archetype<char> Arg2;
660    typedef convertible_to_archetype<Arg1,
661      convertible_to_archetype<Arg2> > FT;
662    typedef convertible_to_archetype<Arg2,
663      convertible_to_archetype<Arg1> > T;
664    typedef forward_iterator_archetype<FT> FIter;
665    FIter fi;
666    T value(dummy_cons);
667    binary_predicate_archetype<Arg1, Arg2> comp(dummy_cons);
668    std::pair<FIter,FIter> p = std::equal_range(fi, fi, value, comp);
669    ignore_unused_variable_warning(p);
670  }
671  {
672#if defined(__GNUC__)  || defined(__IBMCPP__)
673    typedef less_than_op_first_archetype<
674      less_than_op_second_archetype<null_archetype<>, optag2>, optag1> FT;
675    typedef less_than_op_second_archetype<
676      less_than_op_first_archetype<null_archetype<>, optag2>, optag1> T;
677#elif defined(__KCC)
678    typedef less_than_op_first_archetype< less_than_comparable_archetype<> > T;
679    typedef less_than_op_second_archetype< convertible_to_archetype<T> > FT;
680#endif
681    forward_iterator_archetype<FT> fi;
682    T value(dummy_cons);
683    bool b = std::binary_search(fi, fi, value);
684    ignore_unused_variable_warning(b);
685  }
686  {
687    typedef null_archetype<int> Arg1;
688    typedef null_archetype<char> Arg2;
689#if defined(__GNUC__) || defined(__KCC) || defined(__IBMCPP__)
690    typedef convertible_to_archetype<Arg1,
691      convertible_to_archetype<Arg2> > FT;
692    typedef convertible_to_archetype<Arg2,
693      convertible_to_archetype<Arg1> > T;
694#endif
695    typedef forward_iterator_archetype<FT> FIter;
696    FIter fi;
697    T value(dummy_cons);
698    binary_predicate_archetype<Arg1, Arg2> comp(dummy_cons);
699    bool b = std::binary_search(fi, fi, value, comp);
700    ignore_unused_variable_warning(b);
701  }
702  {
703    typedef null_archetype<> Tout;
704#if defined(__GNUC__) || defined(__KCC) || defined(__IBMCPP__)
705    typedef less_than_op_first_archetype<
706      less_than_op_second_archetype<
707      convertible_to_archetype<Tout>, optag2>, optag1 > Tin1;
708    typedef less_than_op_second_archetype<
709      less_than_op_first_archetype<
710      convertible_to_archetype<Tout>, optag2> ,optag1> Tin2;
711#endif
712    // gcc bug
713    input_iterator_archetype<Tin1> in1;
714    input_iterator_archetype<Tin2> in2;
715    output_iterator_archetype<Tout> out(dummy_cons);
716    out = std::merge(in1, in1, in2, in2, out);
717    out = std::set_union(in1, in1, in2, in2, out);
718    out = std::set_intersection(in1, in1, in2, in2, out);
719    out = std::set_difference(in1, in1, in2, in2, out);
720    out = std::set_symmetric_difference(in1, in1, in2, in2, out);
721  }
722  {
723    typedef null_archetype<> T;
724    input_iterator_archetype<T> in1;
725    input_iterator_archetype<T,2> in2;
726    typedef convertible_from_archetype<T> Tout;
727    output_iterator_archetype<T> out(dummy_cons);
728    binary_predicate_archetype<T, T> comp(dummy_cons);
729    out = std::merge(in1, in1, in2, in2, out, comp);
730    out = std::set_union(in1, in1, in2, in2, out, comp);
731    out = std::set_intersection(in1, in1, in2, in2, out, comp);
732    out = std::set_difference(in1, in1, in2, in2, out, comp);
733    out = std::set_symmetric_difference(in1, in1, in2, in2, out, comp);
734  }
735  {
736    typedef sgi_assignable_archetype< 
737      less_than_comparable_archetype<> > T;
738    mutable_bidirectional_iterator_archetype<T> bi;
739    std::inplace_merge(bi, bi, bi);
740  }
741  {
742    typedef null_archetype<> Arg;
743    typedef sgi_assignable_archetype< 
744      convertible_to_archetype<Arg> > T;
745    mutable_bidirectional_iterator_archetype<T> bi;
746    binary_predicate_archetype<Arg, Arg> comp(dummy_cons);
747    std::inplace_merge(bi, bi, bi, comp);
748  }
749  // gcc bug
750  {
751    typedef less_than_op_first_archetype<
752      less_than_op_second_archetype<null_archetype<>, optag1>, optag2> Tin1;
753    typedef less_than_op_second_archetype<
754      less_than_op_first_archetype<null_archetype<>, optag1>, optag2> Tin2;
755    input_iterator_archetype<Tin1> in1;
756    input_iterator_archetype<Tin2> in2;
757    bool b = std::includes(in1, in1, in2, in2);
758    b = std::lexicographical_compare(in1, in1, in2, in2);
759    ignore_unused_variable_warning(b);
760  }
761  {
762    typedef null_archetype<int> Tin;
763    input_iterator_archetype<Tin> in1;
764    input_iterator_archetype<Tin,1> in2;
765    binary_predicate_archetype<Tin, Tin> comp(dummy_cons);
766    bool b = std::includes(in1, in1, in2, in2, comp);
767    b = std::lexicographical_compare(in1, in1, in2, in2, comp);
768    ignore_unused_variable_warning(b);
769  }
770  {
771    typedef sgi_assignable_archetype<
772      less_than_comparable_archetype<> > T;
773    mutable_random_access_iterator_archetype<T> ri;
774    std::push_heap(ri, ri);
775    std::pop_heap(ri, ri);
776    std::make_heap(ri, ri);
777    std::sort_heap(ri, ri);
778  }
779  {
780    typedef null_archetype<> Arg;
781    typedef sgi_assignable_archetype< 
782      convertible_to_archetype<Arg> > T;
783    mutable_random_access_iterator_archetype<T> ri;
784    binary_predicate_archetype<Arg, Arg> comp(dummy_cons);
785    std::push_heap(ri, ri, comp);
786    std::pop_heap(ri, ri, comp);
787    std::make_heap(ri, ri, comp);
788    std::sort_heap(ri, ri, comp);
789  }
790  {
791    typedef less_than_comparable_archetype<> T;
792    T a(dummy_cons), b(dummy_cons);
793    BOOST_USING_STD_MIN();
794    BOOST_USING_STD_MAX();
795    const T& c = min BOOST_PREVENT_MACRO_SUBSTITUTION(a, b);
796    const T& d = max BOOST_PREVENT_MACRO_SUBSTITUTION(a, b);
797    ignore_unused_variable_warning(c);
798    ignore_unused_variable_warning(d);
799  }
800  {
801    typedef null_archetype<> Arg;
802    binary_predicate_archetype<Arg, Arg> comp(dummy_cons);
803    typedef convertible_to_archetype<Arg> T;
804    T a(dummy_cons), b(dummy_cons);
805    BOOST_USING_STD_MIN();
806    BOOST_USING_STD_MAX();
807    const T& c = min BOOST_PREVENT_MACRO_SUBSTITUTION(a, b, comp);
808    const T& d = max BOOST_PREVENT_MACRO_SUBSTITUTION(a, b, comp);
809    ignore_unused_variable_warning(c);
810    ignore_unused_variable_warning(d);
811  }
812  {
813    typedef less_than_comparable_archetype<> T;
814    forward_iterator_archetype<T> fi;
815    fi = std::min_element(fi, fi);
816    fi = std::max_element(fi, fi);
817  }
818  {
819    typedef null_archetype<> Arg;
820    binary_predicate_archetype<Arg, Arg> comp(dummy_cons);
821    typedef convertible_to_archetype<Arg> T;
822    forward_iterator_archetype<T> fi;
823    fi = std::min_element(fi, fi, comp);
824    fi = std::max_element(fi, fi, comp);
825  }
826  {
827    typedef sgi_assignable_archetype<
828      less_than_comparable_archetype<> > T;
829    mutable_bidirectional_iterator_archetype<T> bi;
830    bool b = std::next_permutation(bi, bi);
831    b = std::prev_permutation(bi, bi);
832    ignore_unused_variable_warning(b);
833  }
834  {
835    typedef null_archetype<> Arg;
836    binary_predicate_archetype<Arg, Arg> comp(dummy_cons);
837    typedef sgi_assignable_archetype<
838      convertible_to_archetype<Arg> > T;
839    mutable_bidirectional_iterator_archetype<T> bi;
840    bool b = std::next_permutation(bi, bi, comp);
841    b = std::prev_permutation(bi, bi, comp);
842    ignore_unused_variable_warning(b);
843  }
844  //===========================================================================
845  // Generalized Numeric Algorithms
846
847  {
848    // Bummer, couldn't use plus_op because of a problem with
849    // mutually recursive types.
850    input_iterator_archetype<accum::Tin> in;
851    accum::T init(dummy_cons);
852    init = std::accumulate(in, in, init);
853  }
854  {
855    typedef null_archetype<int> Arg1;
856    typedef null_archetype<char> Arg2;
857    typedef sgi_assignable_archetype<
858      convertible_to_archetype<Arg1> > T;
859    typedef convertible_to_archetype<T> Ret;
860    input_iterator_archetype<Arg2> in;
861    T init(dummy_cons);
862    binary_function_archetype<Arg1, Arg2, Ret> op(dummy_cons);
863    init = std::accumulate(in, in, init, op);
864  }
865  {
866    input_iterator_archetype<inner_prod::Tin1> in1;
867    input_iterator_archetype<inner_prod::Tin2> in2;
868    inner_prod::T init(dummy_cons);
869    init = std::inner_product(in1, in1, in2, init);
870  }
871  {
872    typedef null_archetype<int> MultArg1;
873    typedef null_archetype<char> MultArg2;
874    typedef null_archetype<short> AddArg1;
875    typedef null_archetype<long> AddArg2;
876    typedef sgi_assignable_archetype<
877      convertible_to_archetype<AddArg1> > T;
878    typedef convertible_to_archetype<AddArg2> RetMult;
879    typedef convertible_to_archetype<T> RetAdd;
880    input_iterator_archetype<MultArg1> in1;
881    input_iterator_archetype<MultArg2> in2;
882    T init(dummy_cons);
883    binary_function_archetype<MultArg1, MultArg2, RetMult> mult_op(dummy_cons);
884    binary_function_archetype<AddArg1, AddArg2, RetAdd> add_op(dummy_cons);
885    init = std::inner_product(in1, in1, in2, init, add_op, mult_op);
886  }
887  {
888    input_iterator_archetype<part_sum::T> in;
889    output_iterator_archetype<part_sum::T> out(dummy_cons);
890    out = std::partial_sum(in, in, out);
891  }
892  {
893    typedef sgi_assignable_archetype<> T;
894    input_iterator_archetype<T> in;
895    output_iterator_archetype<T> out(dummy_cons);
896    binary_function_archetype<T, T, T> add_op(dummy_cons);
897    out = std::partial_sum(in, in, out, add_op);
898    binary_function_archetype<T, T, T> subtract_op(dummy_cons);
899    out = std::adjacent_difference(in, in, out, subtract_op);
900  }
901  {
902    input_iterator_archetype<part_sum::T> in;
903    output_iterator_archetype<part_sum::T> out(dummy_cons);
904    out = std::adjacent_difference(in, in, out);
905  }
906  return 0;
907}
Note: See TracBrowser for help on using the repository browser.