diff --git a/sprout/iterator/counting_iterator.hpp b/sprout/iterator/counting_iterator.hpp index 10b6c36a..8ff57ed9 100644 --- a/sprout/iterator/counting_iterator.hpp +++ b/sprout/iterator/counting_iterator.hpp @@ -65,7 +65,7 @@ namespace sprout { : current_(it.current_) {} template - counting_iterator& operator=(counting_iterator const& it) { + SPROUT_CXX14_CONSTEXPR counting_iterator& operator=(counting_iterator const& it) { counting_iterator temp(it); temp.swap(*this); return *this; @@ -76,20 +76,20 @@ namespace sprout { SPROUT_CONSTEXPR pointer operator->() const { return ¤t_; } - counting_iterator& operator++() { + SPROUT_CXX14_CONSTEXPR counting_iterator& operator++() { ++current_; return *this; } - counting_iterator operator++(int) { + SPROUT_CXX14_CONSTEXPR counting_iterator operator++(int) { counting_iterator result(*this); ++current_; return result; } - counting_iterator& operator--() { + SPROUT_CXX14_CONSTEXPR counting_iterator& operator--() { --current_; return *this; } - counting_iterator operator--(int) { + SPROUT_CXX14_CONSTEXPR counting_iterator operator--(int) { counting_iterator temp(*this); --current_; return temp; @@ -100,12 +100,12 @@ namespace sprout { SPROUT_CONSTEXPR counting_iterator operator-(difference_type n) const { return counting_iterator(current_ - n); } - counting_iterator& operator+=(difference_type n) { + SPROUT_CXX14_CONSTEXPR counting_iterator& operator+=(difference_type n) { counting_iterator temp(current_ + n); temp.swap(*this); return *this; } - counting_iterator& operator-=(difference_type n) { + SPROUT_CXX14_CONSTEXPR counting_iterator& operator-=(difference_type n) { counting_iterator temp(current_ - n); temp.swap(*this); return *this; @@ -119,7 +119,7 @@ namespace sprout { SPROUT_CONSTEXPR counting_iterator prev() const { return counting_iterator(current_ - 1); } - void swap(counting_iterator& other) + SPROUT_CXX14_CONSTEXPR void swap(counting_iterator& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(current_, other.current_))) { sprout::swap(current_, other.current_); @@ -184,7 +184,7 @@ namespace sprout { // swap // template - inline void + inline SPROUT_CXX14_CONSTEXPR void swap(sprout::counting_iterator& lhs, sprout::counting_iterator& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { diff --git a/sprout/iterator/generator_iterator.hpp b/sprout/iterator/generator_iterator.hpp index ce9acf1c..84a25cfd 100644 --- a/sprout/iterator/generator_iterator.hpp +++ b/sprout/iterator/generator_iterator.hpp @@ -51,7 +51,7 @@ namespace sprout { ) : gen_(gen), index_(index) {} - generator_type& generator() { + SPROUT_CXX14_CONSTEXPR generator_type& generator() { return gen_; } SPROUT_CONSTEXPR generator_type const& generator() const { @@ -72,7 +72,7 @@ namespace sprout { SPROUT_CONSTEXPR generator_iterator next_generator() const { return (*this)(); } - void swap(generator_iterator& other) + SPROUT_CXX14_CONSTEXPR void swap(generator_iterator& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(gen_, other.gen_))) { sprout::swap(gen_, other.gen_); @@ -84,12 +84,12 @@ namespace sprout { SPROUT_CONSTEXPR pointer operator->() const { return &*(*this); } - generator_iterator& operator++() { + SPROUT_CXX14_CONSTEXPR generator_iterator& operator++() { generator_iterator temp((*this)()); temp.swap(*this); return *this; } - generator_iterator operator++(int) { + SPROUT_CXX14_CONSTEXPR generator_iterator operator++(int) { generator_iterator result(*this); ++*this; return result; @@ -136,7 +136,7 @@ namespace sprout { // swap // template - inline void + inline SPROUT_CXX14_CONSTEXPR void swap(sprout::generator_iterator& lhs, sprout::generator_iterator& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { diff --git a/sprout/iterator/index_iterator.hpp b/sprout/iterator/index_iterator.hpp index 02835e62..edf56131 100644 --- a/sprout/iterator/index_iterator.hpp +++ b/sprout/iterator/index_iterator.hpp @@ -101,7 +101,7 @@ namespace sprout { SPROUT_CONSTEXPR index_iterator(typename holder_type::param_type p, difference_type index) : holder_(p), index_(index) {} - operator index_iterator() const { + SPROUT_CONSTEXPR operator index_iterator() const { return index_iterator(holder_.get(), index_); } SPROUT_CONSTEXPR typename holder_type::mutable_or_const_reference base() const { @@ -116,7 +116,7 @@ namespace sprout { SPROUT_CONSTEXPR index_iterator prev() const { return index_iterator(holder_, index_ - 1); } - void swap(index_iterator& other) + SPROUT_CXX14_CONSTEXPR void swap(index_iterator& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(holder_, other.holder_))) { sprout::swap(holder_, other.holder_); @@ -128,22 +128,22 @@ namespace sprout { SPROUT_CONSTEXPR pointer operator->() const { return &holder_.get()[index_]; } - index_iterator& operator++() { + SPROUT_CXX14_CONSTEXPR index_iterator& operator++() { index_iterator temp(next()); temp.swap(*this); return *this; } - index_iterator operator++(int) { + SPROUT_CXX14_CONSTEXPR index_iterator operator++(int) { index_iterator result(*this); ++*this; return result; } - index_iterator& operator--() { + SPROUT_CXX14_CONSTEXPR index_iterator& operator--() { index_iterator temp(prev()); temp.swap(*this); return *this; } - index_iterator operator--(int) { + SPROUT_CXX14_CONSTEXPR index_iterator operator--(int) { index_iterator result(*this); --*this; return result; @@ -154,12 +154,12 @@ namespace sprout { SPROUT_CONSTEXPR index_iterator operator-(difference_type n) const { return index_iterator(holder_, index_ - n); } - index_iterator& operator+=(difference_type n) { + SPROUT_CXX14_CONSTEXPR index_iterator& operator+=(difference_type n) { index_iterator temp(holder_, index_ + n); temp.swap(*this); return *this; } - index_iterator& operator-=(difference_type n) { + SPROUT_CXX14_CONSTEXPR index_iterator& operator-=(difference_type n) { index_iterator temp(holder_, index_ - n); temp.swap(*this); return *this; @@ -238,7 +238,7 @@ namespace sprout { // swap // template - inline void + inline SPROUT_CXX14_CONSTEXPR void swap(sprout::index_iterator& lhs, sprout::index_iterator& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { diff --git a/sprout/iterator/ptr_index_iterator.hpp b/sprout/iterator/ptr_index_iterator.hpp index 100914bf..3944d62a 100644 --- a/sprout/iterator/ptr_index_iterator.hpp +++ b/sprout/iterator/ptr_index_iterator.hpp @@ -68,7 +68,7 @@ namespace sprout { SPROUT_CONSTEXPR ptr_index_iterator(pointer p, difference_type index) : p_(p), index_(index) {} - operator ptr_index_iterator() const { + SPROUT_CONSTEXPR operator ptr_index_iterator() const { return ptr_index_iterator(p_, index_); } SPROUT_CONSTEXPR pointer base() const { @@ -86,7 +86,7 @@ namespace sprout { SPROUT_CONSTEXPR ptr_index_iterator prev() const { return ptr_index_iterator(p_, index_ - 1); } - void swap(ptr_index_iterator& other) + SPROUT_CXX14_CONSTEXPR void swap(ptr_index_iterator& other) SPROUT_NOEXCEPT { sprout::swap(p_, other.p_); @@ -98,22 +98,22 @@ namespace sprout { SPROUT_CONSTEXPR pointer operator->() const { return p_ + index_; } - ptr_index_iterator& operator++() { + SPROUT_CXX14_CONSTEXPR ptr_index_iterator& operator++() { ptr_index_iterator temp(next()); temp.swap(*this); return *this; } - ptr_index_iterator operator++(int) { + SPROUT_CXX14_CONSTEXPR ptr_index_iterator operator++(int) { ptr_index_iterator result(*this); ++*this; return result; } - ptr_index_iterator& operator--() { + SPROUT_CXX14_CONSTEXPR ptr_index_iterator& operator--() { ptr_index_iterator temp(prev()); temp.swap(*this); return *this; } - ptr_index_iterator operator--(int) { + SPROUT_CXX14_CONSTEXPR ptr_index_iterator operator--(int) { ptr_index_iterator result(*this); --*this; return result; @@ -124,12 +124,12 @@ namespace sprout { SPROUT_CONSTEXPR ptr_index_iterator operator-(difference_type n) const { return ptr_index_iterator(p_, index_ - n); } - ptr_index_iterator& operator+=(difference_type n) { + SPROUT_CXX14_CONSTEXPR ptr_index_iterator& operator+=(difference_type n) { ptr_index_iterator temp(p_, index_ + n); temp.swap(*this); return *this; } - ptr_index_iterator& operator-=(difference_type n) { + SPROUT_CXX14_CONSTEXPR ptr_index_iterator& operator-=(difference_type n) { ptr_index_iterator temp(p_, index_ - n); temp.swap(*this); return *this; @@ -208,7 +208,7 @@ namespace sprout { // swap // template - inline void + inline SPROUT_CXX14_CONSTEXPR void swap(sprout::ptr_index_iterator& lhs, sprout::ptr_index_iterator& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { diff --git a/sprout/iterator/value_iterator.hpp b/sprout/iterator/value_iterator.hpp index da2423e6..3637b238 100644 --- a/sprout/iterator/value_iterator.hpp +++ b/sprout/iterator/value_iterator.hpp @@ -73,7 +73,7 @@ namespace sprout { ) : holder_(p), index_(index) {} - operator value_iterator() const { + SPROUT_CONSTEXPR operator value_iterator() const { return value_iterator(holder_.get(), index_); } SPROUT_CONSTEXPR difference_type index() const { @@ -85,7 +85,7 @@ namespace sprout { SPROUT_CONSTEXPR value_iterator prev() const { return value_iterator(holder_, index_ + 1); } - void swap(value_iterator& other) + SPROUT_CXX14_CONSTEXPR void swap(value_iterator& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(holder_, other.holder_))) { sprout::swap(holder_, other.holder_); @@ -97,22 +97,22 @@ namespace sprout { SPROUT_CONSTEXPR pointer operator->() const { return holder_.get_pointer(); } - value_iterator& operator++() { + SPROUT_CXX14_CONSTEXPR value_iterator& operator++() { value_iterator temp(next()); temp.swap(*this); return *this; } - value_iterator operator++(int) { + SPROUT_CXX14_CONSTEXPR value_iterator operator++(int) { value_iterator result(*this); ++*this; return result; } - value_iterator& operator--() { + SPROUT_CXX14_CONSTEXPR value_iterator& operator--() { value_iterator temp(prev()); temp.swap(*this); return *this; } - value_iterator operator--(int) { + SPROUT_CXX14_CONSTEXPR value_iterator operator--(int) { value_iterator result(*this); --*this; return result; @@ -123,12 +123,12 @@ namespace sprout { SPROUT_CONSTEXPR value_iterator operator-(difference_type n) const { return value_iterator(holder_, index_ + n); } - value_iterator& operator+=(difference_type n) { + SPROUT_CXX14_CONSTEXPR value_iterator& operator+=(difference_type n) { value_iterator temp(holder_, index_ - n); temp.swap(*this); return *this; } - value_iterator& operator-=(difference_type n) { + SPROUT_CXX14_CONSTEXPR value_iterator& operator-=(difference_type n) { value_iterator temp(holder_, index_ + n); temp.swap(*this); return *this; @@ -183,7 +183,7 @@ namespace sprout { // swap // template - inline void + inline SPROUT_CXX14_CONSTEXPR void swap(sprout::value_iterator& lhs, sprout::value_iterator& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { diff --git a/tools/testspr/test.py b/tools/testspr/test.py index a22bf331..52a8903f 100644 --- a/tools/testspr/test.py +++ b/tools/testspr/test.py @@ -25,6 +25,7 @@ def main(): parser.add_option('--clang_root', type='string', default='/usr/local') parser.add_option('--compile_options', type='string', default='') parser.add_option('--test_cpp', type='string') + parser.add_option('--serialized_std_options', type='string', default='{}') parser.add_option('--serialized_version_specific_options', type='string', default='{}') parser.add_option('--max_procs', type='int', default=0) (opts, args) = parser.parse_args() @@ -37,10 +38,12 @@ def main(): compiler = "%s/%s/bin/%s++" % (root, base, name.rstrip('c')) if version != "." else "%s++" % name.rstrip('c') return "%s -o %s" \ " %s %s" \ + " %s" \ " %s > %s 2>&1" \ " && %s > %s 2>&1" \ % (compiler, bin, - opts.compile_options, eval(opts.serialized_version_specific_options).get(base, ''), + eval(opts.serialized_std_options).get(base, ''), opts.compile_options, + eval(opts.serialized_version_specific_options).get(base, ''), opts.test_cpp, compile_log, bin, execute_log ) diff --git a/tools/testspr/test.sh b/tools/testspr/test.sh index 3c0a8415..270567c0 100755 --- a/tools/testspr/test.sh +++ b/tools/testspr/test.sh @@ -19,6 +19,7 @@ declare -a include_paths=() max_procs= force=0 use_help=0 +std="c++11" declare -a common_options=() declare -a version_options=() declare -A version_specific_options=( @@ -27,7 +28,31 @@ declare -A version_specific_options=( test_cpp=$(cd $(dirname $0); pwd)/test.cpp test_py=$(cd $(dirname $0); pwd)/test.py -args=`getopt -o S:g:c:O:V:D:I:P:f -l stagedir:,gcc-version:,clang-version:,gcc-root:,clang-root:,option:,version-option:,define:,include:,max-procs:,force,help -- "$@"` +get_std_option() { + if [ "${3}" = "c++1y" ]; then + if [ "${1}" = "gcc" ]; then + if [ "${2}" = "." ]; then + echo -n "-std=c++1y" + elif [ "${2//.}" -lt "480" ]; then + echo -n "-std=c++11" + else + echo -n "-std=c++1y" + fi + elif [ "${1}" = "clang" ]; then + if [ "${2}" = "." ]; then + echo -n "-std=c++1y" + elif [ "${2//.}" -lt "32" ]; then + echo -n "-std=c++11" + else + echo -n "-std=c++1y" + fi + fi + else + echo -n "-std=c++11" + fi +} + +args=`getopt -o S:g:c:O:V:D:I:P:f -l stagedir:,gcc-version:,clang-version:,gcc-root:,clang-root:,std:,option:,version-option:,define:,include:,max-procs:,force,help -- "$@"` if [ "$?" -ne 0 ]; then echo >&2 "error: options parse error. See 'test.sh --help'" exit 1 @@ -40,6 +65,7 @@ while [ -n "$1" ]; do -c|--clang-version) clang_version="$2"; shift 2;; --gcc-root) gcc_root="$2"; shift 2;; --clang-root) clang_root="$2"; shift 2;; + --std) std="$2"; shift 2;; -O|--option) common_options=("${common_options[@]}" "$2"); shift 2;; -V|--version-option) version_options=("${version_options[@]}" "$2"); shift 2;; -D|--define) user_macros=("${user_macros[@]}" "$2"); shift 2;; @@ -72,6 +98,9 @@ if [ ${use_help} -ne 0 ]; then echo " --clang-root= Root directory that clang installed." echo " Default; '/usr/local'" echo "" + echo " --std= Standard C++ version." + echo " Default; 'c++11'" + echo "" echo " -O, --option= Add compile option." echo "" echo " -V, --version-option= Add version specific compile option." @@ -97,6 +126,7 @@ echo " gcc-version = (${gcc_version})" echo " clang-version = (${clang_version})" echo " gcc-root = '${gcc_root}'" echo " clang-root = '${clang_root}'" +echo " std = '${std}'" echo " common-options = (${common_options[*]})" echo " version-options = (${version_options[*]})" echo " user-macros = (${user_macros[*]})" @@ -110,7 +140,7 @@ done for include_path in ${include_paths}; do include_options="${include_options} -I${include_path}" done -compile_options="-v -Wall -pedantic -std=c++11 ${define_options} ${include_options} ${common_options[*]}" +compile_options="-v -Wall -pedantic ${define_options} ${include_options} ${common_options[*]}" vo=0 vkey="" for option in ${version_options}; do @@ -172,11 +202,13 @@ compile() { if [ -z "${max_procs}" ]; then fail_count=0 for version in ${gcc_version}; do - compile "gcc" "${version}" "${test_cpp}" "${compile_options}" "${gcc_root}" + std_option=`get_std_option "gcc" "${version}" "${std}"` + compile "gcc" "${version}" "${test_cpp}" "${std_option} ${compile_options}" "${gcc_root}" let fail_count=${fail_count}+$? done for version in ${clang_version}; do - compile "clang" "${version}" "${test_cpp}" "${compile_options}" "${clang_root}" + std_option=`get_std_option "clang" "${version}" "${std}"` + compile "clang" "${version}" "${test_cpp}" "${std_option} ${compile_options}" "${clang_root}" let fail_count=${fail_count}+$? done if [ ${fail_count} -ne 0 ]; then @@ -193,11 +225,33 @@ else done echo \'_\':\'\' `} + serialized_std_options={` + for version in ${gcc_version}; do + if [ "${version}" = "." ]; then + echo -n \'gcc\':\' + else + echo -n \'gcc-${version}\':\' + fi + get_std_option "gcc" "${version}" "${std}" + echo \', + done + for version in ${clang_version}; do + if [ "${version}" = "." ]; then + echo -n \'clang\':\' + else + echo -n \'clang-${version}\':\' + fi + get_std_option "clang" "${version}" "${std}" + echo \', + done + echo \'_\':\'\' + `} python "${test_py}" \ "--stagedir=${stagedir}" \ "--gcc_version=${gcc_version}" "--clang_version=${clang_version}" \ "--gcc_root=${gcc_root}" "--clang_root=${clang_root}" \ "--compile_options=${compile_options}" "--test_cpp=${test_cpp}" \ + "--serialized_std_options=${serialized_std_options}" \ "--serialized_version_specific_options=${serialized_version_specific_options}" \ "--max_procs=${max_procs}" fail_count=$?