diff --git a/.travis.yml b/.travis.yml index 512fc4c..d81670b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,18 +13,19 @@ matrix: include: - os: linux dist: trusty - env: CC=gcc-7 CXX=g++-7 BOOST_ROOT=/usr/include/boost + env: CC=gcc-8 CXX=g++-8 BOOST_ROOT=/usr/include/boost compiler: gcc before_install: - sudo -E apt-add-repository -y "ppa:ubuntu-toolchain-r/test" - sudo apt-get update - - sudo apt-get install g++-7 + - sudo apt-get install g++-8 - export BOOST_URL="https://downloads.sourceforge.net/project/boost/boost/1.67.0/boost_1_67_0.tar.gz" - mkdir -p /tmp/boost - wget --quiet -O - ${BOOST_URL} | tar --strip-components=1 -xz -C /tmp/boost || exit 1 - cd /tmp/boost/tools/build && ./bootstrap.sh && ./b2 install --prefix=/tmp/b2 - export PATH=/tmp/b2/bin:${PATH} - - cd /tmp/boost && b2 toolset=gcc cxxflags="-std=c++14 ${CXXFLAGS}" + - cd /tmp/boost && b2 toolset=gcc cxxflags="-std=c++17 ${CXXFLAGS}" + install: export CXX="g++-8" - os: osx osx_image: xcode9.4 env: diff --git a/include/real/real.hpp b/include/real/real.hpp index 21b6dd2..7a3a513 100644 --- a/include/real/real.hpp +++ b/include/real/real.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -59,11 +60,8 @@ namespace boost { KIND _kind; - // Explicit number - real_explicit _explicit_number; - - // Algorithmic number - real_algorithm _algorithmic_number; + std::variant _explicit_algorithm_number; + //Stores both explicit and algorithmic numbers // Composed number OPERATION _operation; @@ -103,11 +101,10 @@ namespace boost { // Internal number to iterate real const* _real_ptr = nullptr; - // Explicit number iterator - boost::real::real_explicit::const_precision_iterator _explicit_it; + std::variant _explicit_algorithm_it; + //Stores both explicit and algorithmic iterators - // Algorithmic number iterator - boost::real::real_algorithm::const_precision_iterator _algorithmic_it; // If the number is a composition, the const_precision_iterator uses the operand iterators const_precision_iterator* _lhs_it_ptr = nullptr; @@ -303,13 +300,17 @@ namespace boost { switch (this->_real_ptr->_kind) { case KIND::EXPLICIT: - this->_explicit_it = this->_real_ptr->_explicit_number.cbegin(); - this->approximation_interval = this->_explicit_it.approximation_interval; + this->_explicit_algorithm_it = std::get( + this->_real_ptr->_explicit_algorithm_number).cbegin(); + this->approximation_interval = std::get +(this -> _explicit_algorithm_it).approximation_interval; break; case KIND::ALGORITHM: - this->_algorithmic_it = this->_real_ptr->_algorithmic_number.cbegin(); - this->approximation_interval = this->_algorithmic_it.approximation_interval; + this->_explicit_algorithm_it = std::get + (this->_real_ptr->_explicit_algorithm_number).cbegin(); + this->approximation_interval = std::get +(this->_explicit_algorithm_it).approximation_interval; break; case KIND::OPERATION: @@ -339,20 +340,27 @@ namespace boost { case KIND::EXPLICIT: if (cend) { - this->_explicit_it = this->_real_ptr->_explicit_number.cend(); + this->_explicit_algorithm_it = std::get + (this->_real_ptr->_explicit_algorithm_number).cend(); } else { - this->_explicit_it = this->_real_ptr->_explicit_number.cbegin(); + this->_explicit_algorithm_it= + std::get + (this->_real_ptr->_explicit_algorithm_number).cbegin(); } - this->approximation_interval = this->_explicit_it.approximation_interval; + this->approximation_interval = std::get +(this->_explicit_algorithm_it).approximation_interval; break; case KIND::ALGORITHM: if (cend) { - this->_algorithmic_it = this->_real_ptr->_algorithmic_number.cend(); + this->_explicit_algorithm_it = std::get( + this->_real_ptr->_explicit_algorithm_number).cend(); } else { - this->_algorithmic_it = this->_real_ptr->_algorithmic_number.cbegin(); + this->_explicit_algorithm_it = std::get + (this->_real_ptr->_explicit_algorithm_number).cbegin(); } - this->approximation_interval = this->_algorithmic_it.approximation_interval; + this->approximation_interval = std::get +(this->_explicit_algorithm_it).approximation_interval; break; case KIND::OPERATION: @@ -372,13 +380,17 @@ namespace boost { switch (this->_real_ptr->_kind) { case KIND::EXPLICIT: - ++this->_explicit_it; - this->approximation_interval = this->_explicit_it.approximation_interval; + ++(std::get + (this->_explicit_algorithm_it)); + this->approximation_interval = std::get + (this->_explicit_algorithm_it).approximation_interval; break; case KIND::ALGORITHM: - ++this->_algorithmic_it; - this->approximation_interval = this->_algorithmic_it.approximation_interval; + ++(std::get + (this->_explicit_algorithm_it)); + this->approximation_interval = std::get + (this->_explicit_algorithm_it).approximation_interval; break; case KIND::OPERATION: @@ -440,8 +452,7 @@ namespace boost { */ real(const real& other) : _kind(other._kind), - _explicit_number(other._explicit_number), - _algorithmic_number(other._algorithmic_number), + _explicit_algorithm_number(other._explicit_algorithm_number), _operation(other._operation) { this->copy_operands(other); }; /** @@ -454,7 +465,7 @@ namespace boost { * @throws boost::real::invalid_string_number exception */ real(const std::string& number) - : _kind(KIND::EXPLICIT), _explicit_number(number) {} + : _kind(KIND::EXPLICIT), _explicit_algorithm_number(std::in_place_type, number) {} /** * @brief *Initializer list constructor:* Creates a boost::real::real_explicit instance @@ -464,7 +475,8 @@ namespace boost { * @param digits - a initializer_list that represents the number digits. */ real(std::initializer_list digits) - : _kind(KIND::EXPLICIT), _explicit_number(digits, digits.size()) {} + : _kind(KIND::EXPLICIT), _explicit_algorithm_number + (std::in_place_type, digits, digits.size()) {} /** @@ -478,7 +490,8 @@ namespace boost { * the number is positive, otherwise is negative. */ real(std::initializer_list digits, bool positive) - : _kind(KIND::EXPLICIT), _explicit_number(digits, digits.size(), positive) {} + : _kind(KIND::EXPLICIT), _explicit_algorithm_number + (std::in_place_type, digits, digits.size(), positive) {} /** * @brief *Initializer list constructor with exponent:* Creates a boost::real::real @@ -490,7 +503,8 @@ namespace boost { * @param exponent - an integer representing the number exponent. */ real(std::initializer_list digits, int exponent) - : _kind(KIND::EXPLICIT), _explicit_number(digits, exponent) {}; + : _kind(KIND::EXPLICIT), _explicit_algorithm_number + (std::in_place_type, digits, exponent) {}; /** * @brief *Initializer list constructor with exponent and sign:* Creates a boost::real::real instance @@ -504,7 +518,8 @@ namespace boost { * the number is positive, otherwise is negative. */ real(std::initializer_list digits, int exponent, bool positive) - : _kind(KIND::EXPLICIT), _explicit_number(digits, exponent, positive) {}; + : _kind(KIND::EXPLICIT), _explicit_algorithm_number + (std::in_place_type, digits, exponent, positive) {}; /** * @brief *Lambda function constructor with exponent:* Creates a boost::real::real @@ -517,7 +532,8 @@ namespace boost { * @param exponent - an integer representing the number exponent. */ real(int (*get_nth_digit)(unsigned int), int exponent) - : _kind(KIND::ALGORITHM), _algorithmic_number(get_nth_digit, exponent) {} + : _kind(KIND::ALGORITHM), _explicit_algorithm_number + (std::in_place_type, get_nth_digit, exponent) {} /** * @brief *Lambda function constructor with exponent and sign:* Creates a boost::real::real instance @@ -536,7 +552,8 @@ namespace boost { int exponent, bool positive) : _kind(KIND::ALGORITHM), - _algorithmic_number(get_nth_digit, exponent, positive) {} + _explicit_algorithm_number + (std::in_place_type, get_nth_digit, exponent, positive) {} /** * @brief *Default destructor:* If the number is an operator, the destructor destroys its operands. @@ -616,11 +633,11 @@ namespace boost { switch (this->_kind) { case KIND::EXPLICIT: - result = this->_explicit_number[n]; + result = std::get(this -> _explicit_algorithm_number)[n]; break; case KIND::ALGORITHM: - result = this->_algorithmic_number[n]; + result = std::get(this->_explicit_algorithm_number)[n]; break; case KIND::OPERATION: @@ -729,7 +746,7 @@ namespace boost { */ real& operator=(const real& other) { this->_kind = other._kind; - this->_explicit_number = other._explicit_number; + this->_explicit_algorithm_number = other._explicit_algorithm_number; this->_operation = other._operation; this->copy_operands(other); return *this;