functions_interval_construct.qbk 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. [/
  2. Copyright (c) 2008-2010 Joachim Faulhaber
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt)
  6. ]
  7. [/ //= Interval Construction ===================================================================]
  8. [section Interval Construction]
  9. [table
  10. [[T] [__ch_dsc_itv__] [__ch_cnt_itv__] [__ch_ro_itv__] [__ch_lo_itv__] [__ch_cl_itv__] [__ch_op_itv__] ]
  11. [[Interval bounds] [dynamic] [dynamic] [static] [static] [static] [static] ]
  12. [[Form] [ ] [ ] [asymmetric] [asymmetric] [symmetric] [symmetric] ]
  13. [[['*Construct*]] [ ] [ ] [ ] [ ] [ ] [ ] ]
  14. [[`T singleton(const P&)`] [__d] [__c] [__d] [__d] [__d] [__d] ]
  15. [[`T construct(const P&, const P&)`] [__d] [__c] [__dc] [__dc] [__d] [__d] ]
  16. [[``
  17. T construct(const P&, const P&,
  18. interval_bounds )
  19. ``] [__d] [__c] [ ] [ ] [ ] [ ] ]
  20. [[`T hull(const P&, const P&)`] [__d] [__c] [__dc] [__dc] [__d] [__d] ]
  21. [[`T span(const P&, const P&)`] [__d] [__c] [__dc] [__dc] [__d] [__d] ]
  22. [[`static T right_open(const P&, const P&)`] [__d] [__c] [ ] [ ] [ ] [ ] ]
  23. [[`static T left_open(const P&, const P&)`] [__d] [__c] [ ] [ ] [ ] [ ] ]
  24. [[`static T closed(const P&, const P&)`] [__d] [__c] [ ] [ ] [ ] [ ] ]
  25. [[`static T open(const P&, const P&)`] [__d] [__c] [ ] [ ] [ ] [ ] ]
  26. ]
  27. The table above shows the availability of functions, that allow the construction
  28. of intervals. All interval constructin functins are of ['*constant time and space complexity*].
  29. [table
  30. [[['*Construct*]] [Description] ]
  31. [[`T singleton(const P& value)`] [Constructs an interval that contains exactly one element `value`.
  32. For all interval types of the icl sigletons can be constructed
  33. for /discrete/ domain types. For continuous domain types, only
  34. __ct_itv__ is capable to construct a singleton. ] ]
  35. [[`T construct(const P& lower, const P& upper)`] [Contructs an interval with lower bound `lower` and upper bound `upper` ] ]
  36. [[``
  37. T construct(const P& lower, const P& upper,
  38. interval_bounds bounds
  39. = interval_bounds::right_open())
  40. ``]
  41. [For dynamically bounded intervals this function constructs an
  42. interval with interval bounds specified by the third parameter. ] ]
  43. [[`T hull(const P& x1, const P& x2)`] [`hull(x1,x2)` constructs the smallest interval that contains both `x1` and `x2`.
  44. `x2` may be smaller than `x1`. ] ]
  45. [[`T span(const P& x1, const P& x2)`] [`span(x1,x2)` constructs the interval `construct(min(x1,x2), max(x1,x2))`.
  46. Note the differences between `span`, `hull` and `construct`:
  47. ``
  48. span<right_open_interval<int> >(2,1) == [1,2) // does NOT contain 2
  49. hull<right_open_interval<int> >(2,1) == [1,3) // contains 2
  50. construct<right_open_interval<int> >(2,1) == [) // is empty
  51. ``
  52. ] ]
  53. [[``
  54. static T right_open(const P&, const P&)
  55. static T left_open(const P&, const P&)
  56. static T closed(const P&, const P&)
  57. static T open(const P&, const P&)
  58. `` ] [For dynamically bounded intervals there are for static functions to
  59. construct intervals with the four interval bound types:
  60. ``
  61. discrete_interval<int> itv1 = discrete_interval<int>::closed(0,42);
  62. continuous_interval<double> itv2 = continuous_interval<double>::right_open(0.0, 1.0);
  63. ``
  64. ] ]
  65. [[['*Using the interval default*]] [ ]]
  66. [[`interval<P>::type`] [There is a library default, for all interval containers of the *icl*.
  67. The intension of the library default is to minimize the need for parameter
  68. specification, when working with *icl* class templates.
  69. We can get the library default interval type as `interval<P>::type`.
  70. The library default uses ['*dynamically bounded intervals*]. You
  71. can switch to ['*statically bounded intervals*] by
  72. `#define BOOST_ICL_USE_STATIC_BOUNDED_INTERVALS` prior to icl includes. ]]
  73. [[``
  74. static T right_open(const P&, const P&)
  75. static T left_open(const P&, const P&)
  76. static T closed(const P&, const P&)
  77. static T open(const P&, const P&)
  78. `` ] [For template struct `interval` that always uses the library default
  79. the static functions for the four interval bound types are also available.
  80. ``
  81. interval<int>::type itv1 = interval<int>::closed(0,42);
  82. interval<double>::type itv2 = interval<double>::right_open(0.0, 1.0);
  83. ``
  84. This works with the statically bounded intervals as well,
  85. with the restriction that for continuous domain types the
  86. matching function has to be used:
  87. ``
  88. #define BOOST_ICL_USE_STATIC_BOUNDED_INTERVALS
  89. . . .
  90. // library default is the statically bounded right_open_interval
  91. interval<int>::type itv1 = interval<int>::closed(0,42); //==[0,43) //ok, bounds are shifted
  92. interval<double>::type itv2 = interval<double>::right_open(0.0, 1.0); //ok. right_open matches
  93. interval<double>::type itv3 = interval<double>::closed(0.0, 1.0); //will NOT compile
  94. ``
  95. See also examples
  96. [link boost_icl.examples.dynamic_interval Dynamic intervals] and
  97. [link boost_icl.examples.static_interval Static intervals]
  98. ]]
  99. ]
  100. ['*See also . . .*]
  101. [table
  102. []
  103. [[[link boost_icl.examples.dynamic_interval ['*Example: Dynamically bounded intervals and the library default*]] ]]
  104. [[[link boost_icl.examples.static_interval ['*Example: Statically bounded intervals, changing the library default*]] ]]
  105. ]
  106. ['*Back to section . . .*]
  107. [table
  108. []
  109. [[[link additional_interval_functions ['*Additional interval functions*]] ]]
  110. [[[link function_synopsis_table ['*Function Synopsis*]] ]]
  111. [[[link boost_icl.interface ['*Interface*]] ]]
  112. ]
  113. [endsect][/ Interval Construction]