getting_started.qbk 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. [/ Copyright (C) 2008-2018 Lorenzo Caminiti]
  2. [/ Distributed under the Boost Software License, Version 1.0 (see accompanying]
  3. [/ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).]
  4. [/ See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html]
  5. [section Getting Started]
  6. This section shows how to setup and start using this library.
  7. [section This Documentation]
  8. Programmers should be able to start using this library after reading the __Introduction__, __Getting_Started__, and __Tutorial__.
  9. Other sections of this documentation (e.g., __Advanced__ and __Extras__) can be consulted at a later point to gain a more in-depth knowledge of the library.
  10. __Contract_Programming_Overview__ can be skipped by programmers that are already familiar with the contract programming methodology.
  11. Some of the source code listed in this documentation contains special code comments of the form `//[...` and `//]`.
  12. These mark sections of the code that are automatically extracted from the source code and presented as part of this documentation.
  13. [footnote
  14. *Rationale:*
  15. This allows to make sure that most of the example code presented in this documentation is always up-to-date, builds and runs with the latest implementation of the library.
  16. ]
  17. It should be noted that the purpose of all examples of this documentation is to illustrate how to use this library and not to show real production code.
  18. Some footnotes are marked by the word "*Rationale*".
  19. These explain some of the decisions made during the design and implementation of this library.
  20. [endsect]
  21. [section Compilers and Platforms]
  22. In general, this library requires C++ compilers with a sound implementation of SFINAE and other template meta-programming techniques supported by the C++03 standard.
  23. It is possible to use this library without C++11 lambda functions but a large amount of boiler-plate code is required to manually program separate functors to specify preconditions, postconditions, etc. (so using this library without C++11 lambda functions is possible but not recommended, see __No_Lambda_Functions__).
  24. It is also possible to use this library without variadic macros by manually programming a small amount of boiler-plate code (but most if not all modern C++ compilers support variadic macros even before C++99 and C++11 so this should never be needed in practice, see __No_Macros__).
  25. Some parts of this documentation use the syntax [^['type-of](...)] to indicate an operator logically equivalent to C++11 `decltype(...)`.
  26. However, this library implementation does not actually use type deduction in these cases (because the library internally already knows the types in question) so support for C++11 `decltype` and other type-of implementations are not actually required (that is why [^['type-of]] and not the real `decltype` operator is used in this documentation).
  27. This library has been developed and tested using:
  28. * Visual Studio 2015 on Windows (MSVC =cl= version 19.00.24215.1).
  29. * GCC version 5.4.0 on Cygwin (with C++11 features enabled =-std=c++11=).
  30. * Clang version 3.8.1 on Cygwin (with C++11 features enabled =-std=c++11=).
  31. For information on other compilers and platforms see the library [@http://www.boost.org/development/tests/master/developer/contract.html regression tests].
  32. The development and maintenance of this library is hosted on [@https://github.com/boostorg/contract GitHub].
  33. [endsect]
  34. [section Code Organization]
  35. Let [^['boost-root]] be the directory where Boost source files were installed.
  36. This library flies are organized as follows:
  37. [pre
  38. ['boost-root]\/libs\/contract # Directory where this library files are.
  39. build/ # Build files (using BJam).
  40. doc/ # Documentation (using Boost.QuickBook).
  41. example/ # Examples (also those listed in this documentation).
  42. include/ # DO NOT USE: Use copies of these files from
  43. boost/ # ['boost-root]\/boost/ instead:
  44. contract.hpp # - Include all headers at once.
  45. contract_macro.hpp # - Include library macro interface.
  46. contract/ # - Header files that can be included one-by-one.
  47. core/ # - Fundamental headers (usually indirectly included by other headers).
  48. detail/ # - Implementation code (should never be included or used directly).
  49. src/ # Library source code to be compiled.
  50. test/ # Tests.
  51. ]
  52. All headers required by this library can be included at once by:
  53. #include <boost/contract.hpp>
  54. Or, by the following when using the library macro interface (see __Disable_Contract_Compilation__):
  55. #include <boost/contract_macro.hpp>
  56. Alternatively, all =boost/contract/*.hpp= headers are independent from one another and they can be selectively included one-by-one based on the specific functionality of this library being used (but this was measured to not make an appreciable difference in compile-time so =boost/contract.hpp= can be included directly in most cases).
  57. The =boost/contract/core/*.hpp= headers are not independent from other headers and they do not need to be directly included in user code when =boost/contract.hpp= or =boost/contract/*.hpp= headers are included already.
  58. All files under =boost/contract/detail/=, names in the `boost::contract::detail` namespace, macros starting with `BOOST_CONTRACT_DETAIL...`, and all names starting with `boost_contract_detail...` (in any namespace, including user-defined namespaces) are part of this library implementation and should never be used directly in user code.
  59. Names starting with `BOOST_CONTRACT_ERROR...` are used by this library to report some compile-time errors (so spotting these names in compiler error messages might help troubleshooting).
  60. [endsect]
  61. [section Build]
  62. Let [^['boost-root]] be the directory where Boost source files were installed.
  63. This library is installed and compiled as part of Boost using BJam.
  64. [warning
  65. It is strongly recommended to compile and use this library as a shared library (a.k.a., Dynamically Linked Library or DLL) by defining the `BOOST_ALL_DYN_LINK` macro (or at least [macroref BOOST_CONTRACT_DYN_LINK]) when building Boost.
  66. When using BJam to build Boost, this can be achieved by the `link=shared` parameter (which is already the default so no extra parameter is actually needed for `bjam`).
  67. It is also possible to compile and use this library as a static library (by defining the [macroref BOOST_CONTRACT_STATIC_LINK] macro) or as a header-only library (by leaving both [macroref BOOST_CONTRACT_DYN_LINK] and [macroref BOOST_CONTRACT_STATIC_LINK] undefined).
  68. However, this library is not guaranteed to always work correctly in these cases.
  69. Specifically, this library might not correctly disable contracts while checking other contracts and call the correct user-defined contract failure handlers unless it is compiled as a shared library when it is used across different program units (different programs, different shared libraries in the same program, etc.).
  70. ]
  71. [heading Linux-Based Systems]
  72. For example, to build all Boost libraries including this one (as shared libraries, see also [@https://www.boost.org/doc/libs/1_70_0/more/getting_started Boost documentation]):
  73. [pre
  74. $ cd ['boost-root]
  75. $ .\/bootstrap.sh
  76. $ .\/bjam
  77. ]
  78. To compile and run the [@../../example/features/introduction.cpp [^['boost-root]\/libs/contract/example/features/introduction.cpp]] example:
  79. [pre
  80. $ cd ['boost-root]\/libs/contract/example
  81. $ ..\/..\/..\/bjam features-introduction
  82. ]
  83. To compile and run all this library's tests (this might take while):
  84. [pre
  85. $ cd ['boost-root]\/libs/contract/test
  86. $ ..\/..\/..\/bjam
  87. ]
  88. To compile and run code that uses this library but without BJam (similarly for Clang):
  89. [pre
  90. $ cd /tmp
  91. $ g++ -std=c++11 -D BOOST_CONTRACT_DYN_LINK -I ['boost-root] ['boost-root]\/stage/lib/['system-prefix]boost_contract.dll ['boost-root]\/libs/contract/example/features/introduction.cpp -o introduction
  92. $ export PATH=$PATH:['boost-root]\/stage/lib
  93. $ ./introduction
  94. ]
  95. [heading Windows-Based Systems]
  96. For example, to build all Boost libraries including this one (as DLLs, see also [@https://www.boost.org/doc/libs/1_70_0/more/getting_started Boost documentation]):
  97. [pre
  98. >cd ['boost-root]
  99. >bootstrap.bat
  100. >bjam
  101. ]
  102. To compile and run the [@../../example/features/introduction.cpp [^['boost-root]\/libs/contract/example/features/introduction.cpp]] example:
  103. [pre
  104. >cd ['boost-root]\libs\contract\example
  105. >..\\..\\..\\bjam features-introduction
  106. ]
  107. To compile and run all this library's tests (this might take while):
  108. [pre
  109. >cd ['boost-root]\libs\contract\test
  110. >..\\..\\..\\bjam
  111. ]
  112. To compile and run code that uses this library but without BJam:
  113. [pre
  114. >cd C:\Temp
  115. >cl /MDd /EHs /std:c++11 /D BOOST_CONTRACT_DYN_LINK /I ['boost-root] /link /DLL /LIBPATH:['boost-root]\stage\lib ['boost-root]\libs\contract\example\features\introduction.cpp /out:introduction
  116. >set PATH=%PATH%;['boost-root]\/stage/lib
  117. >introduction
  118. ]
  119. [endsect]
  120. [endsect]