diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /src/boost/libs/logic | |
parent | Initial commit. (diff) | |
download | ceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/logic')
-rw-r--r-- | src/boost/libs/logic/CMakeLists.txt | 17 | ||||
-rw-r--r-- | src/boost/libs/logic/Jamfile | 10 | ||||
-rw-r--r-- | src/boost/libs/logic/LICENSE | 23 | ||||
-rw-r--r-- | src/boost/libs/logic/README.md | 34 | ||||
-rw-r--r-- | src/boost/libs/logic/index.html | 16 | ||||
-rw-r--r-- | src/boost/libs/logic/meta/libraries.json | 16 | ||||
-rw-r--r-- | src/boost/libs/logic/test/Jamfile.v2 | 62 | ||||
-rw-r--r-- | src/boost/libs/logic/test/compile-fail/implicit.cpp | 23 | ||||
-rw-r--r-- | src/boost/libs/logic/test/compile-fail/implicit_int_1.cpp | 16 | ||||
-rw-r--r-- | src/boost/libs/logic/test/compile-fail/implicit_int_2.cpp | 16 | ||||
-rw-r--r-- | src/boost/libs/logic/test/compile-fail/implicit_int_3.cpp | 16 | ||||
-rw-r--r-- | src/boost/libs/logic/test/compile-fail/operator_less_1.cpp | 16 | ||||
-rw-r--r-- | src/boost/libs/logic/test/compile-fail/operator_less_2.cpp | 15 | ||||
-rw-r--r-- | src/boost/libs/logic/test/compile/decl_header.cpp | 24 | ||||
-rw-r--r-- | src/boost/libs/logic/test/tribool_io_test.cpp | 210 | ||||
-rw-r--r-- | src/boost/libs/logic/test/tribool_rename_test.cpp | 122 | ||||
-rw-r--r-- | src/boost/libs/logic/test/tribool_test.cpp | 154 |
17 files changed, 790 insertions, 0 deletions
diff --git a/src/boost/libs/logic/CMakeLists.txt b/src/boost/libs/logic/CMakeLists.txt new file mode 100644 index 000000000..ce2f4f3d6 --- /dev/null +++ b/src/boost/libs/logic/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright 2018 Mike Dev +# Distributed under 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 + +cmake_minimum_required( VERSION 3.5...3.20 ) +project( boost_logic VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX ) + +add_library( boost_logic INTERFACE ) +add_library( Boost::logic ALIAS boost_logic ) + +target_include_directories( boost_logic INTERFACE include ) + +target_link_libraries( boost_logic + INTERFACE + Boost::config + Boost::core +) diff --git a/src/boost/libs/logic/Jamfile b/src/boost/libs/logic/Jamfile new file mode 100644 index 000000000..df4894635 --- /dev/null +++ b/src/boost/libs/logic/Jamfile @@ -0,0 +1,10 @@ +# Boost.Logic Library Jamfile +# +# Copyright (c) 2018 James E. King III +# +# Use, modification, and distribution are 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) + +# please order by name to ease maintenance +build-project test ; diff --git a/src/boost/libs/logic/LICENSE b/src/boost/libs/logic/LICENSE new file mode 100644 index 000000000..36b7cd93c --- /dev/null +++ b/src/boost/libs/logic/LICENSE @@ -0,0 +1,23 @@ +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/src/boost/libs/logic/README.md b/src/boost/libs/logic/README.md new file mode 100644 index 000000000..a71ecd322 --- /dev/null +++ b/src/boost/libs/logic/README.md @@ -0,0 +1,34 @@ +Logic, part of collection of the [Boost C++ Libraries](http://github.com/boostorg), provides `boost::logic::tribool` for 3-state boolean logic. + +### License + +Distributed under the [Boost Software License, Version 1.0](http://www.boost.org/LICENSE_1_0.txt). + +### Properties + +* C++03 +* Header Only + +### Build Status + +Branch | Travis | Appveyor | Coverity Scan | codecov.io | Deps | Docs | Tests | +:-------------: | ------ | -------- | ------------- | ---------- | ---- | ---- | ----- | +[`master`](https://github.com/boostorg/logic/tree/master) | [![Build Status](https://travis-ci.org/boostorg/logic.svg?branch=master)](https://travis-ci.org/boostorg/logic) | [![Build status](https://ci.appveyor.com/api/projects/status/a898pj8spmo2t3x9/branch/master?svg=true)](https://ci.appveyor.com/project/jeking3/logic-vv3ct/branch/master) | [![Coverity Scan Build Status](https://scan.coverity.com/projects/16173/badge.svg)](https://scan.coverity.com/projects/boostorg-logic) | [![codecov](https://codecov.io/gh/boostorg/logic/branch/master/graph/badge.svg)](https://codecov.io/gh/boostorg/logic/branch/master)| [![Deps](https://img.shields.io/badge/deps-master-brightgreen.svg)](https://pdimov.github.io/boostdep-report/master/logic.html) | [![Documentation](https://img.shields.io/badge/docs-master-brightgreen.svg)](http://www.boost.org/doc/libs/master/doc/html/logic.html) | [![Enter the Matrix](https://img.shields.io/badge/matrix-master-brightgreen.svg)](http://www.boost.org/development/tests/master/developer/logic.html) +[`develop`](https://github.com/boostorg/logic/tree/develop) | [![Build Status](https://travis-ci.org/boostorg/logic.svg?branch=develop)](https://travis-ci.org/boostorg/logic) | [![Build status](https://ci.appveyor.com/api/projects/status/a898pj8spmo2t3x9/branch/develop?svg=true)](https://ci.appveyor.com/project/jeking3/logic-vv3ct/branch/develop) | [![Coverity Scan Build Status](https://scan.coverity.com/projects/16173/badge.svg)](https://scan.coverity.com/projects/boostorg-logic) | [![codecov](https://codecov.io/gh/boostorg/logic/branch/develop/graph/badge.svg)](https://codecov.io/gh/boostorg/logic/branch/develop) | [![Deps](https://img.shields.io/badge/deps-develop-brightgreen.svg)](https://pdimov.github.io/boostdep-report/develop/logic.html) | [![Documentation](https://img.shields.io/badge/docs-develop-brightgreen.svg)](http://www.boost.org/doc/libs/develop/doc/html/logic.html) | [![Enter the Matrix](https://img.shields.io/badge/matrix-develop-brightgreen.svg)](http://www.boost.org/development/tests/develop/developer/logic.html) + +### Directories + +| Name | Purpose | +| ----------- | ------------------------------ | +| `doc` | documentation | +| `example` | examples | +| `include` | headers | +| `test` | unit tests | + +### More information + +* [Ask questions](http://stackoverflow.com/questions/ask?tags=c%2B%2B,boost,boost-logic) +* [Report bugs](https://github.com/boostorg/logic/issues): Be sure to mention Boost version, platform and compiler you're using. A small compilable code sample to reproduce the problem is always good as well. +* Submit your patches as pull requests against **develop** branch. Note that by submitting patches you agree to license your modifications under the [Boost Software License, Version 1.0](http://www.boost.org/LICENSE_1_0.txt). +* Discussions about the library are held on the [Boost developers mailing list](http://www.boost.org/community/groups.html#main). Be sure to read the [discussion policy](http://www.boost.org/community/policy.html) before posting and add the `[logic]` tag at the beginning of the subject line. + diff --git a/src/boost/libs/logic/index.html b/src/boost/libs/logic/index.html new file mode 100644 index 000000000..6ae39d47f --- /dev/null +++ b/src/boost/libs/logic/index.html @@ -0,0 +1,16 @@ + +<!-- +Copyright 2011 Daniel James. +Distributed under 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) +--> + +<html> +<head> + <meta http-equiv="refresh" content="0; URL=../../doc/html/tribool.html"> +</head> +<body> +Automatic redirection failed, please go to +<a href="../../doc/html/tribool.html">../../doc/html/tribool.html</a> +</body> +</html> diff --git a/src/boost/libs/logic/meta/libraries.json b/src/boost/libs/logic/meta/libraries.json new file mode 100644 index 000000000..31504c2fd --- /dev/null +++ b/src/boost/libs/logic/meta/libraries.json @@ -0,0 +1,16 @@ +{ + "key": "logic/tribool", + "name": "Tribool", + "authors": [ + "Doug Gregor" + ], + "description": "3-state boolean type library.", + "documentation": "/doc/html/tribool.html", + "category": [ + "Miscellaneous" + ], + "maintainers": [ + "Douglas Gregor <dgregor -at- cs.indiana.edu>" + ], + "cxxstd": "03" +} diff --git a/src/boost/libs/logic/test/Jamfile.v2 b/src/boost/libs/logic/test/Jamfile.v2 new file mode 100644 index 000000000..994f2b6b5 --- /dev/null +++ b/src/boost/libs/logic/test/Jamfile.v2 @@ -0,0 +1,62 @@ +# Tribool library + +# Copyright (C) 2002-2003 Douglas Gregor + +# 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) + +# For more information, see http://www.boost.org/ + +import path ; +import os ; +import regex ; +import testing ; + +local self = logic ; + +rule test-expected-failures +{ + local all_rules = ; + local file ; + local tests_path = [ path.make $(BOOST_ROOT)/libs/$(self)/test/compile-fail ] ; + for file in [ path.glob-tree $(tests_path) : *.cpp ] + { + local rel_file = [ path.relative-to $(tests_path) $(file) ] ; + local test_name = [ regex.replace [ regex.replace $(rel_file) "/" "-" ] ".cpp" "" ] ; + local decl_test_name = cf-$(test_name) ; + # ECHO $(rel_file) ; + all_rules += [ compile-fail $(file) : : $(decl_test_name) ] ; + } + + # ECHO All rules: $(all_rules) ; + return $(all_rules) ; +} + +rule test-header-isolation +{ + local all_rules = ; + local file ; + local headers_path = [ path.make $(BOOST_ROOT)/libs/$(self)/include ] ; + for file in [ path.glob-tree $(headers_path) : *.hpp ] + { + local rel_file = [ path.relative-to $(headers_path) $(file) ] ; + # Note: The test name starts with '~' in order to group these tests in the test report table, preferably at the end. + # All '/' are replaced with '-' because apparently test scripts have a problem with test names containing slashes. + local test_name = [ regex.replace $(rel_file) "/" "-" ] ; + local decl_test_name = ~hdr-decl-$(test_name) ; + # ECHO $(rel_file) ; + all_rules += [ compile compile/decl_header.cpp : <define>"BOOST_TEST_HEADER=$(rel_file)" <dependency>$(file) : $(decl_test_name) ] ; + } + + # ECHO All rules: $(all_rules) ; + return $(all_rules) ; +} + + test-suite logic : + [ test-expected-failures ] + [ test-header-isolation ] + [ run tribool_test.cpp ] + [ run tribool_rename_test.cpp ] + [ run tribool_io_test.cpp ] + ; diff --git a/src/boost/libs/logic/test/compile-fail/implicit.cpp b/src/boost/libs/logic/test/compile-fail/implicit.cpp new file mode 100644 index 000000000..ba56bfb86 --- /dev/null +++ b/src/boost/libs/logic/test/compile-fail/implicit.cpp @@ -0,0 +1,23 @@ +// Copyright 2018 James E. King III. 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) + +#include <boost/logic/tribool.hpp> + +int main(int, char*[]) +{ + using boost::logic::indeterminate; + using boost::logic::tribool; + + tribool i(indeterminate); + +#if !defined( BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS ) + bool b = i; // expect to see: no viable conversion from 'boost::logic::tribool' to 'bool' + return (int)b; +#else +#error in c++03 explicit conversions are allowed +#endif + // NOTREACHED + return 0; +} diff --git a/src/boost/libs/logic/test/compile-fail/implicit_int_1.cpp b/src/boost/libs/logic/test/compile-fail/implicit_int_1.cpp new file mode 100644 index 000000000..4e889550c --- /dev/null +++ b/src/boost/libs/logic/test/compile-fail/implicit_int_1.cpp @@ -0,0 +1,16 @@ +// Copyright 2018 James E. King III. 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) + +#include <boost/logic/tribool.hpp> + +int main(int, char*[]) +{ + using boost::logic::indeterminate; + using boost::logic::tribool; + + tribool i(indeterminate); + + return i; // expect to see: error: no viable conversion from returned value of type 'boost::logic::tribool' to function return type 'int' +} diff --git a/src/boost/libs/logic/test/compile-fail/implicit_int_2.cpp b/src/boost/libs/logic/test/compile-fail/implicit_int_2.cpp new file mode 100644 index 000000000..1401caaa7 --- /dev/null +++ b/src/boost/libs/logic/test/compile-fail/implicit_int_2.cpp @@ -0,0 +1,16 @@ +// Copyright 2018 James E. King III. 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) + +#include <boost/logic/tribool.hpp> + +int main(int, char*[]) +{ + using boost::logic::indeterminate; + using boost::logic::tribool; + + tribool i(indeterminate); + + return i + 1; // expect to see: error: invalid operands to binary expression ('boost::logic::tribool' and 'int') +} diff --git a/src/boost/libs/logic/test/compile-fail/implicit_int_3.cpp b/src/boost/libs/logic/test/compile-fail/implicit_int_3.cpp new file mode 100644 index 000000000..b6548c5a8 --- /dev/null +++ b/src/boost/libs/logic/test/compile-fail/implicit_int_3.cpp @@ -0,0 +1,16 @@ +// Copyright 2018 James E. King III. 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) + +#include <boost/logic/tribool.hpp> + +int main(int, char*[]) +{ + using boost::logic::indeterminate; + using boost::logic::tribool; + + tribool i(indeterminate); + + return i << 1; // expect to see: error: invalid operands to binary expression ('boost::logic::tribool' and 'int') +} diff --git a/src/boost/libs/logic/test/compile-fail/operator_less_1.cpp b/src/boost/libs/logic/test/compile-fail/operator_less_1.cpp new file mode 100644 index 000000000..31be7aeef --- /dev/null +++ b/src/boost/libs/logic/test/compile-fail/operator_less_1.cpp @@ -0,0 +1,16 @@ +// Copyright 2018 James E. King III. 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) + +#include <boost/logic/tribool.hpp> + +int main(int, char*[]) +{ + using boost::logic::tribool; + + tribool f; // false + tribool t(true); // true + + return f < t; // expect to see: error: invalid operands to binary expression ('boost::logic::tribool' and 'boost::logic::tribool') +} diff --git a/src/boost/libs/logic/test/compile-fail/operator_less_2.cpp b/src/boost/libs/logic/test/compile-fail/operator_less_2.cpp new file mode 100644 index 000000000..53fc359a8 --- /dev/null +++ b/src/boost/libs/logic/test/compile-fail/operator_less_2.cpp @@ -0,0 +1,15 @@ +// Copyright 2018 James E. King III. 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) + +#include <boost/logic/tribool.hpp> + +int main(int, char*[]) +{ + using boost::logic::tribool; + + tribool t(true); + + return t < 1; // expect to see: error: invalid operands to binary expression ('boost::logic::tribool' and 'int') +} diff --git a/src/boost/libs/logic/test/compile/decl_header.cpp b/src/boost/libs/logic/test/compile/decl_header.cpp new file mode 100644 index 000000000..2a2862618 --- /dev/null +++ b/src/boost/libs/logic/test/compile/decl_header.cpp @@ -0,0 +1,24 @@ +/* + * Copyright Andrey Semashev 2015. + * Distributed under 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) + */ +/*! + * \file decl_header.cpp + * \author Andrey Semashev + * \date 21.06.2015 + * + * \brief This file contains a test boilerplate for checking that every + * public header is self-contained and does not have any missing + * #includes. + */ + +#define BOOST_TEST_INCLUDE_HEADER() <BOOST_TEST_HEADER> + +#include BOOST_TEST_INCLUDE_HEADER() + +int main(int, char*[]) +{ + return 0; +} diff --git a/src/boost/libs/logic/test/tribool_io_test.cpp b/src/boost/libs/logic/test/tribool_io_test.cpp new file mode 100644 index 000000000..a2e19b105 --- /dev/null +++ b/src/boost/libs/logic/test/tribool_io_test.cpp @@ -0,0 +1,210 @@ +// Copyright Douglas Gregor 2002-2004. 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) +#include <boost/logic/tribool.hpp> +#include <boost/logic/tribool_io.hpp> +#include <boost/core/lightweight_test.hpp> +#include <sstream> +#include <string> +#include <iostream> +#include <ios> // for std::boolalpha + +#ifndef BOOST_NO_STD_LOCALE +# include <locale> +#endif + +int main() +{ + using namespace boost::logic; + + tribool x; + + #if !defined(BOOST_NO_CWCHAR) && !defined(BOOST_NO_STD_WSTRING) + std::wostringstream wout; + wout << std::boolalpha << tribool(false); + BOOST_TEST(wout.str() == L"false"); + wout.str(std::wstring()); + wout << std::boolalpha << tribool(true); + BOOST_TEST(wout.str() == L"true"); + wout.str(std::wstring()); + wout << std::boolalpha << tribool(indeterminate); + BOOST_TEST(wout.str() == L"indeterminate"); + #endif + + // Check tribool output + std::ostringstream out; + + // Output false (noboolalpha) + out.str(std::string()); + x = false; + out << x; + std::cout << "Output false (noboolalpha): " << out.str() << std::endl; + BOOST_TEST(out.str() == "0"); + + // Output true (noboolalpha) + out.str(std::string()); + x = true; + out << x; + std::cout << "Output true (noboolalpha): " << out.str() << std::endl; + BOOST_TEST(out.str() == "1"); + + // Output indeterminate (noboolalpha) + out.str(std::string()); + x = indeterminate; + out << x; + std::cout << "Output indeterminate (noboolalpha): " << out.str() + << std::endl; + BOOST_TEST(out.str() == "2"); + + // Output indeterminate (noboolalpha) + out.str(std::string()); + out << indeterminate; + std::cout << "Output indeterminate (noboolalpha): " << out.str() + << std::endl; + BOOST_TEST(out.str() == "2"); + +#ifndef BOOST_NO_STD_LOCALE + const std::numpunct<char>& punct = + BOOST_USE_FACET(std::numpunct<char>, out.getloc()); + + // Output false (boolalpha) + out.str(std::string()); + x = false; + out << std::boolalpha << x; + std::cout << "Output false (boolalpha): " << out.str() << std::endl; + BOOST_TEST(out.str() == punct.falsename()); + + // Output true (boolalpha) + out.str(std::string()); + x = true; + out << std::boolalpha << x; + std::cout << "Output true (boolalpha): " << out.str() << std::endl; + + BOOST_TEST(out.str() == punct.truename()); + + // Output indeterminate (boolalpha - default name) + out.str(std::string()); + x = indeterminate; + out << std::boolalpha << x; + std::cout << "Output indeterminate (boolalpha - default name): " << out.str() + << std::endl; + BOOST_TEST(out.str() == "indeterminate"); + + // Output indeterminate (boolalpha - default name) + out.str(std::string()); + out << std::boolalpha << indeterminate; + std::cout << "Output indeterminate (boolalpha - default name): " << out.str() + << std::endl; + BOOST_TEST(out.str() == "indeterminate"); + +# if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) + // No template constructors, so we can't build the test locale +# else + // Give indeterminate a new name, and output it via boolalpha + std::locale global; + std::locale test_locale(global, new indeterminate_name<char>("maybe")); + out.imbue(test_locale); + out.str(std::string()); + out << std::boolalpha << x; + std::cout << "Output indeterminate (boolalpha - \"maybe\"): " << out.str() + << std::endl; + BOOST_TEST(out.str() == "maybe"); +# endif +#endif // ! BOOST_NO_STD_LOCALE + + // Checking tribool input + + // Input false (noboolalpha) + { + std::istringstream in("0"); + std::cout << "Input \"0\" (checks for false)" << std::endl; + in >> x; + BOOST_TEST(x == false); + } + + // Input true (noboolalpha) + { + std::istringstream in("1"); + std::cout << "Input \"1\" (checks for true)" << std::endl; + in >> x; + BOOST_TEST(x == true); + } + + // Input false (noboolalpha) + { + std::istringstream in("2"); + std::cout << "Input \"2\" (checks for indeterminate)" << std::endl; + in >> x; + BOOST_TEST(indeterminate(x)); + } + + // Input bad number (noboolalpha) + { + std::istringstream in("3"); + std::cout << "Input \"3\" (checks for failure)" << std::endl; + BOOST_TEST(!(in >> x)); + } + + // Input false (boolalpha) + { + std::istringstream in("false"); + std::cout << "Input \"false\" (checks for false)" << std::endl; + in >> std::boolalpha >> x; + BOOST_TEST(x == false); + } + + // Input true (boolalpha) + { + std::istringstream in("true"); + std::cout << "Input \"true\" (checks for true)" << std::endl; + in >> std::boolalpha >> x; + BOOST_TEST(x == true); + } + + // Input indeterminate (boolalpha) + { + std::istringstream in("indeterminate"); + std::cout << "Input \"indeterminate\" (checks for indeterminate)" + << std::endl; + in >> std::boolalpha >> x; + BOOST_TEST(indeterminate(x)); + } + + // Input bad string (boolalpha) + { + std::istringstream in("bad"); + std::cout << "Input \"bad\" (checks for failure)" + << std::endl; + BOOST_TEST(!(in >> std::boolalpha >> x)); + } + +#if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) + // No template constructors, so we can't build the test locale +#elif !defined(BOOST_NO_STD_LOCALE) + + // Input indeterminate named "maybe" (boolalpha) + { + std::istringstream in("maybe"); + in.imbue(test_locale); + std::cout << "Input \"maybe\" (checks for indeterminate, uses locales)" + << std::endl; + in >> std::boolalpha >> x; + BOOST_TEST(indeterminate(x)); + } + + // Input indeterminate named "true_or_false" (boolalpha) + { + std::locale my_locale(global, + new indeterminate_name<char>("true_or_false")); + std::istringstream in("true_or_false"); + in.imbue(my_locale); + std::cout << "Input \"true_or_false\" (checks for indeterminate)" + << std::endl; + in >> std::boolalpha >> x; + BOOST_TEST(indeterminate(x)); + } +#endif + + return boost::report_errors(); +} diff --git a/src/boost/libs/logic/test/tribool_rename_test.cpp b/src/boost/libs/logic/test/tribool_rename_test.cpp new file mode 100644 index 000000000..3d016e0a0 --- /dev/null +++ b/src/boost/libs/logic/test/tribool_rename_test.cpp @@ -0,0 +1,122 @@ +// Copyright Douglas Gregor 2002-2003. 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) + +// For more information, see http://www.boost.org + +#include <boost/logic/tribool.hpp> +#include <boost/core/lightweight_test.hpp> +#include <iostream> + +BOOST_TRIBOOL_THIRD_STATE(maybe) + +int main() +{ + using namespace boost::logic; + + tribool x; // false + tribool y(true); // true + tribool z(maybe); // maybe + + BOOST_TEST(!x); + BOOST_TEST(x == false); + BOOST_TEST(false == x); + BOOST_TEST(x != true); + BOOST_TEST(true != x); + BOOST_TEST(maybe(x == maybe)); + BOOST_TEST(maybe(maybe == x)); + BOOST_TEST(maybe(x != maybe)); + BOOST_TEST(maybe(maybe != x)); + BOOST_TEST(x == x); + BOOST_TEST(!(x != x)); + BOOST_TEST(!(x && true)); + BOOST_TEST(!(true && x)); + BOOST_TEST(x || true); + BOOST_TEST(true || x); + + BOOST_TEST(y); + BOOST_TEST(y == true); + BOOST_TEST(true == y); + BOOST_TEST(y != false); + BOOST_TEST(false != y); + BOOST_TEST(maybe(y == maybe)); + BOOST_TEST(maybe(maybe == y)); + BOOST_TEST(maybe(y != maybe)); + BOOST_TEST(maybe(maybe != y)); + BOOST_TEST(y == y); + BOOST_TEST(!(y != y)); + + BOOST_TEST(maybe(z || !z)); + BOOST_TEST(maybe(z == true)); + BOOST_TEST(maybe(true == z)); + BOOST_TEST(maybe(z == false)); + BOOST_TEST(maybe(false == z)); + BOOST_TEST(maybe(z == maybe)); + BOOST_TEST(maybe(maybe == z)); + BOOST_TEST(maybe(z != maybe)); + BOOST_TEST(maybe(maybe != z)); + BOOST_TEST(maybe(z == z)); + BOOST_TEST(maybe(z != z)); + + BOOST_TEST(!(x == y)); + BOOST_TEST(x != y); + BOOST_TEST(maybe(x == z)); + BOOST_TEST(maybe(x != z)); + BOOST_TEST(maybe(y == z)); + BOOST_TEST(maybe(y != z)); + + BOOST_TEST(!(x && y)); + BOOST_TEST(x || y); + BOOST_TEST(!(x && z)); + BOOST_TEST(maybe(y && z)); + BOOST_TEST(maybe(z && z)); + BOOST_TEST(maybe(z || z)); + BOOST_TEST(maybe(x || z)); + BOOST_TEST(y || z); + + BOOST_TEST(maybe(y && maybe)); + BOOST_TEST(maybe(maybe && y)); + BOOST_TEST(!(x && maybe)); + BOOST_TEST(!(maybe && x)); + + BOOST_TEST(maybe || y); + BOOST_TEST(y || maybe); + BOOST_TEST(maybe(x || maybe)); + BOOST_TEST(maybe(maybe || x)); + + // Test the if (z) ... else (!z) ... else ... idiom + if (z) { + BOOST_TEST(false); + } + else if (!z) { + BOOST_TEST(false); + } + else { + BOOST_TEST(true); + } + + z = true; + if (z) { + BOOST_TEST(true); + } + else if (!z) { + BOOST_TEST(false); + } + else { + BOOST_TEST(false); + } + + z = false; + if (z) { + BOOST_TEST(false); + } + else if (!z) { + BOOST_TEST(true); + } + else { + BOOST_TEST(false); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/logic/test/tribool_test.cpp b/src/boost/libs/logic/test/tribool_test.cpp new file mode 100644 index 000000000..2a90949a5 --- /dev/null +++ b/src/boost/libs/logic/test/tribool_test.cpp @@ -0,0 +1,154 @@ +// Copyright Douglas Gregor 2002-2003. 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) + +#include <boost/config.hpp> +#include <boost/logic/tribool.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/static_assert.hpp> +#include <iostream> + +int main() +{ + using namespace boost::logic; + + tribool x; // false + tribool y(true); // true + tribool z(indeterminate); // indeterminate + +#if defined( BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS ) + // c++03 allows for implicit conversion to bool + // c++11 uses an explicit conversion operator so this would not compile + // and that is tested in the compile-fail/implicit.cpp file + // so we check the conversion to ensure it is sane + bool bx = x; + BOOST_TEST(bx == false); + bool by = y; + BOOST_TEST(by == true); + bool bz = z; + BOOST_TEST(bz == false); +#endif + + BOOST_TEST(!x); + BOOST_TEST(x == false); + BOOST_TEST(false == x); + BOOST_TEST(x != true); + BOOST_TEST(true != x); + BOOST_TEST(indeterminate(x == indeterminate)); + BOOST_TEST(indeterminate(indeterminate == x)); + BOOST_TEST(indeterminate(x != indeterminate)); + BOOST_TEST(indeterminate(indeterminate != x)); + BOOST_TEST(x == x); + BOOST_TEST(!(x != x)); + BOOST_TEST(!(x && true)); + BOOST_TEST(!(true && x)); + BOOST_TEST(x || true); + BOOST_TEST(true || x); + + BOOST_TEST(y); + BOOST_TEST(y == true); + BOOST_TEST(true == y); + BOOST_TEST(y != false); + BOOST_TEST(false != y); + BOOST_TEST(indeterminate(y == indeterminate)); + BOOST_TEST(indeterminate(indeterminate == y)); + BOOST_TEST(indeterminate(y != indeterminate)); + BOOST_TEST(indeterminate(indeterminate != y)); + BOOST_TEST(y == y); + BOOST_TEST(!(y != y)); + + BOOST_TEST(indeterminate(z || !z)); + BOOST_TEST(indeterminate(z == true)); + BOOST_TEST(indeterminate(true == z)); + BOOST_TEST(indeterminate(z == false)); + BOOST_TEST(indeterminate(false == z)); + BOOST_TEST(indeterminate(z == indeterminate)); + BOOST_TEST(indeterminate(indeterminate == z)); + BOOST_TEST(indeterminate(z != indeterminate)); + BOOST_TEST(indeterminate(indeterminate != z)); + BOOST_TEST(indeterminate(z == z)); + BOOST_TEST(indeterminate(z != z)); + + BOOST_TEST(!(x == y)); + BOOST_TEST(x != y); + BOOST_TEST(indeterminate(x == z)); + BOOST_TEST(indeterminate(x != z)); + BOOST_TEST(indeterminate(y == z)); + BOOST_TEST(indeterminate(y != z)); + + BOOST_TEST(!(x && y)); + BOOST_TEST(x || y); + BOOST_TEST(!(x && z)); + BOOST_TEST(indeterminate(y && z)); + BOOST_TEST(indeterminate(z && z)); + BOOST_TEST(indeterminate(z || z)); + BOOST_TEST(indeterminate(x || z)); + BOOST_TEST(y || z); + + BOOST_TEST(indeterminate(y && indeterminate)); + BOOST_TEST(indeterminate(indeterminate && y)); + BOOST_TEST(!(x && indeterminate)); + BOOST_TEST(!(indeterminate && x)); + + BOOST_TEST(indeterminate || y); + BOOST_TEST(y || indeterminate); + BOOST_TEST(indeterminate(x || indeterminate)); + BOOST_TEST(indeterminate(indeterminate || x)); + + // Test the if (z) ... else (!z) ... else ... idiom + if (z) { + BOOST_TEST(false); + } + else if (!z) { + BOOST_TEST(false); + } + else { + BOOST_TEST(true); + } + + z = true; + if (z) { + BOOST_TEST(true); + } + else if (!z) { + BOOST_TEST(false); + } + else { + BOOST_TEST(false); + } + + z = false; + if (z) { + BOOST_TEST(false); + } + else if (!z) { + BOOST_TEST(true); + } + else { + BOOST_TEST(false); + } + +#if !defined(BOOST_NO_CXX11_CONSTEXPR) + constexpr bool res_ors = indeterminate(false || tribool(false) || false || indeterminate); // true + BOOST_TEST(res_ors); + char array_ors[res_ors ? 2 : 3]; + BOOST_TEST(sizeof(array_ors) / sizeof(char) == 2); + + constexpr bool res_ands = !indeterminate(!(true && tribool(true) && true && indeterminate)); // false + BOOST_TEST(!res_ands); + char array_ands[res_ands ? 2 : 3]; + BOOST_TEST(sizeof(array_ands) / sizeof(char) == 3); + + constexpr bool res_safe_bool = static_cast<bool>( tribool(true) ); + BOOST_STATIC_ASSERT(res_safe_bool); + +// gcc 4.6 chokes on the xxx assignment +# if !BOOST_WORKAROUND(BOOST_GCC, < 40700) + constexpr tribool xxx = (tribool(true) || tribool(indeterminate)); + BOOST_STATIC_ASSERT(xxx); +# endif +#endif + + return boost::report_errors(); +} |