diff --git a/_clang-format b/_clang-format index f92d007..555e3b7 100644 --- a/_clang-format +++ b/_clang-format @@ -54,4 +54,4 @@ IncludeCategories: Priority: 40 # Boost specific stuff -ForEachMacros: [ BOOST_FOREACH ] +ForEachMacros: [ BOOST_FOREACH, QUICKBOOK_FOR ] diff --git a/src/actions.cpp b/src/actions.cpp index f13e451..24f42e1 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -25,6 +24,7 @@ #include "block_tags.hpp" #include "document_state.hpp" #include "files.hpp" +#include "for.hpp" #include "grammar.hpp" #include "markups.hpp" #include "path.hpp" @@ -103,7 +103,7 @@ namespace quickbook if (qbk_version_n >= 107u) { char const* allowed_punctuation = "_.-"; - BOOST_FOREACH (char c, id) { + QUICKBOOK_FOR (char c, id) { if (!std::isalnum(c) && !std::strchr(allowed_punctuation, c)) valid = false; @@ -692,7 +692,7 @@ namespace quickbook state.out << markup.pre; - BOOST_FOREACH (value item, list) { + QUICKBOOK_FOR (value item, list) { state.out << ""; state.out << item.get_encoded(); state.out << ""; @@ -892,7 +892,7 @@ namespace quickbook value_consumer values = image; attributes["fileref"] = values.consume(); - BOOST_FOREACH (value pair_, values) { + QUICKBOOK_FOR (value pair_, values) { value_consumer pair = pair_; value name = pair.consume(); value value = pair.consume(); @@ -1035,7 +1035,7 @@ namespace quickbook state.phrase << " template_values; - BOOST_FOREACH (value const& p, values.consume()) { + QUICKBOOK_FOR (value const& p, values.consume()) { template_values.push_back(p.get_quickbook().to_s()); } @@ -1413,7 +1413,7 @@ namespace quickbook std::vector args; - BOOST_FOREACH (value arg, values) { + QUICKBOOK_FOR (value arg, values) { args.push_back(arg); } @@ -1563,7 +1563,7 @@ namespace quickbook detail::print_string(title, state.out.get()); state.out << "\n"; - BOOST_FOREACH (value_consumer entry, values) { + QUICKBOOK_FOR (value_consumer entry, values) { state.out << ""; if (entry.check()) { @@ -1574,7 +1574,7 @@ namespace quickbook if (entry.check()) { state.out << ""; - BOOST_FOREACH (value phrase, entry) + QUICKBOOK_FOR (value phrase, entry) state.out << phrase.get_encoded(); state.out << ""; } @@ -1624,7 +1624,7 @@ namespace quickbook int span_count = 0; value_consumer lookahead = values; - BOOST_FOREACH (value row, lookahead) { + QUICKBOOK_FOR (value row, lookahead) { ++row_count; span_count = boost::distance(row); } @@ -1654,7 +1654,7 @@ namespace quickbook if (row_count > 1) { state.out << "" << ""; - BOOST_FOREACH (value cell, values.consume()) { + QUICKBOOK_FOR (value cell, values.consume()) { state.out << "" << cell.get_encoded() << ""; } state.out << "\n" @@ -1663,9 +1663,9 @@ namespace quickbook state.out << "\n"; - BOOST_FOREACH (value row, values) { + QUICKBOOK_FOR (value row, values) { state.out << ""; - BOOST_FOREACH (value cell, row) { + QUICKBOOK_FOR (value cell, row) { state.out << "" << cell.get_encoded() << ""; } state.out << "\n"; @@ -1858,7 +1858,7 @@ namespace quickbook state.templates.push(); } - BOOST_FOREACH (template_symbol& ts, storage) { + QUICKBOOK_FOR (template_symbol& ts, storage) { std::string tname = ts.identifier; if (tname != "!") { ts.lexical_parent = &state.templates.top_scope(); @@ -1872,7 +1872,7 @@ namespace quickbook } if (load_type == block_tags::include) { - BOOST_FOREACH (template_symbol& ts, storage) { + QUICKBOOK_FOR (template_symbol& ts, storage) { std::string tname = ts.identifier; if (tname == "!") { @@ -1898,7 +1898,7 @@ namespace quickbook std::set search = include_search(parameter, state, first); - BOOST_FOREACH (quickbook_path const& path, search) { + QUICKBOOK_FOR (quickbook_path const& path, search) { try { if (qbk_version_n >= 106) { if (state.imported && diff --git a/src/dependency_tracker.cpp b/src/dependency_tracker.cpp index 6ef932c..5f50352 100644 --- a/src/dependency_tracker.cpp +++ b/src/dependency_tracker.cpp @@ -9,7 +9,7 @@ #include "dependency_tracker.hpp" #include #include -#include +#include "for.hpp" #include "path.hpp" namespace quickbook @@ -23,7 +23,7 @@ namespace quickbook std::string result; result.reserve(generic.size()); - BOOST_FOREACH (char c, generic) { + QUICKBOOK_FOR (char c, generic) { if (c >= 0 && c < 16) { result += control_escapes[(unsigned int)c]; } @@ -98,15 +98,15 @@ namespace quickbook void dependency_tracker::write_dependencies(std::ostream& out, flags f) { if (f & checked) { - BOOST_FOREACH (dependency_list::value_type const& d, dependencies) { + QUICKBOOK_FOR (dependency_list::value_type const& d, dependencies) { out << (d.second ? "+ " : "- ") << get_path(d.first, f) << std::endl; } - BOOST_FOREACH (glob_list::value_type const& g, glob_dependencies) { + QUICKBOOK_FOR (glob_list::value_type const& g, glob_dependencies) { out << "g " << get_path(g.first, f) << std::endl; - BOOST_FOREACH (fs::path const& p, g.second) { + QUICKBOOK_FOR (fs::path const& p, g.second) { out << "+ " << get_path(p, f) << std::endl; } } @@ -114,19 +114,19 @@ namespace quickbook else { std::set paths; - BOOST_FOREACH (dependency_list::value_type const& d, dependencies) { + QUICKBOOK_FOR (dependency_list::value_type const& d, dependencies) { if (d.second) { paths.insert(get_path(d.first, f)); } } - BOOST_FOREACH (glob_list::value_type const& g, glob_dependencies) { - BOOST_FOREACH (fs::path const& p, g.second) { + QUICKBOOK_FOR (glob_list::value_type const& g, glob_dependencies) { + QUICKBOOK_FOR (fs::path const& p, g.second) { paths.insert(get_path(p, f)); } } - BOOST_FOREACH (std::string const& p, paths) { + QUICKBOOK_FOR (std::string const& p, paths) { out << p << std::endl; } } diff --git a/src/doc_info_actions.cpp b/src/doc_info_actions.cpp index d9cbc75..7bfb162 100644 --- a/src/doc_info_actions.cpp +++ b/src/doc_info_actions.cpp @@ -12,10 +12,10 @@ #include #include #include -#include #include "doc_info_tags.hpp" #include "document_state.hpp" #include "files.hpp" +#include "for.hpp" #include "path.hpp" #include "quickbook.hpp" #include "state.hpp" @@ -414,7 +414,7 @@ namespace quickbook if (!authors.empty()) { tmp << " \n"; - BOOST_FOREACH (value_consumer author_values, authors) { + QUICKBOOK_FOR (value_consumer author_values, authors) { while (author_values.check()) { value surname = author_values.consume(doc_info_tags::author_surname); @@ -432,7 +432,7 @@ namespace quickbook tmp << " \n"; } - BOOST_FOREACH (value_consumer copyright, copyrights) { + QUICKBOOK_FOR (value_consumer copyright, copyrights) { while (copyright.check()) { tmp << "\n" << " \n"; @@ -487,7 +487,7 @@ namespace quickbook << "\n"; } - BOOST_FOREACH (value_consumer category_values, categories) { + QUICKBOOK_FOR (value_consumer category_values, categories) { value category = category_values.optional_consume(); if (!category.empty()) { tmp << " <" << doc_type << "category name=\"category:" @@ -498,7 +498,7 @@ namespace quickbook category_values.finish(); } - BOOST_FOREACH (value_consumer biblioid, biblioids) { + QUICKBOOK_FOR (value_consumer biblioid, biblioids) { value class_ = biblioid.consume(doc_info_tags::biblioid_class); value value_ = biblioid.consume(doc_info_tags::biblioid_value); @@ -508,7 +508,7 @@ namespace quickbook biblioid.finish(); } - BOOST_FOREACH (value escaped, escaped_attributes) { + QUICKBOOK_FOR (value escaped, escaped_attributes) { tmp << "" << escaped.get_quickbook() << ""; } diff --git a/src/doc_info_grammar.cpp b/src/doc_info_grammar.cpp index 6e2c5db..b3ca44a 100644 --- a/src/doc_info_grammar.cpp +++ b/src/doc_info_grammar.cpp @@ -9,7 +9,6 @@ =============================================================================*/ #include -#include #include #include #include @@ -19,6 +18,7 @@ #include #include "actions.hpp" #include "doc_info_tags.hpp" +#include "for.hpp" #include "grammar_impl.hpp" #include "phrase_tags.hpp" #include "state.hpp" @@ -99,12 +99,12 @@ namespace quickbook local.doc_types = "book", "article", "library", "chapter", "part", "appendix", "preface", "qandadiv", "qandaset", "reference", "set"; - BOOST_FOREACH (value::tag_type t, doc_attributes::tags()) { + QUICKBOOK_FOR (value::tag_type t, doc_attributes::tags()) { local.doc_attributes.add(doc_attributes::name(t), t); local.doc_info_attributes.add(doc_attributes::name(t), t); } - BOOST_FOREACH (value::tag_type t, doc_info_attributes::tags()) { + QUICKBOOK_FOR (value::tag_type t, doc_info_attributes::tags()) { local.doc_info_attributes.add(doc_info_attributes::name(t), t); } diff --git a/src/files.cpp b/src/files.cpp index 05de077..59af301 100644 --- a/src/files.cpp +++ b/src/files.cpp @@ -12,10 +12,10 @@ #include #include #include -#include #include #include #include +#include "for.hpp" namespace quickbook { diff --git a/src/for.hpp b/src/for.hpp new file mode 100644 index 0000000..dd5a1a8 --- /dev/null +++ b/src/for.hpp @@ -0,0 +1,25 @@ +/*============================================================================= + Copyright (c) 2017 Daniel James + + 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) +=============================================================================*/ + +// Macro for C++11 range based for loop, with BOOST_FOREACH as a fallback. +// Can't use C++11 loop in Visual C++ 10/Visual Studio 2010 or gcc 4.4. +// BOOST_FOREACH was causing warnings in Visual C++ 14.11/Visual Studio 2017 + +#if !defined(BOOST_QUICKBOOK_FOR_HPP) +#define BOOST_QUICKBOOK_FOR_HPP + +#include + +#if !defined(BOOST_NO_CXX11_RANGE_BASED_FOR) +#define QUICKBOOK_FOR(x, y) for (x : y) +#else +#include +#define QUICKBOOK_FOR(x, y) BOOST_FOREACH (x, y) +#endif + +#endif diff --git a/src/id_generation.cpp b/src/id_generation.cpp index f640d19..de6f352 100644 --- a/src/id_generation.cpp +++ b/src/id_generation.cpp @@ -7,12 +7,12 @@ =============================================================================*/ #include -#include #include #include #include #include #include "document_state_impl.hpp" +#include "for.hpp" namespace quickbook { @@ -132,7 +132,7 @@ namespace quickbook placeholder_index sorted_placeholders; sorted_placeholders.reserve(state.placeholders.size()); - BOOST_FOREACH (id_placeholder const& p, state.placeholders) + QUICKBOOK_FOR (id_placeholder const& p, state.placeholders) if (order[p.index]) sorted_placeholders.push_back(&p); boost::sort(sorted_placeholders, placeholder_compare(order)); diff --git a/src/include_paths.cpp b/src/include_paths.cpp index 32d6d8a..a04d655 100644 --- a/src/include_paths.cpp +++ b/src/include_paths.cpp @@ -12,8 +12,8 @@ #include "include_paths.hpp" #include #include -#include #include +#include "for.hpp" #include "glob.hpp" #include "path.hpp" #include "quickbook.hpp" // For the include_path global (yuck) @@ -206,7 +206,7 @@ namespace quickbook // Search the include path dirs accumulating to the result. unsigned count = 0; - BOOST_FOREACH (fs::path dir, include_path) { + QUICKBOOK_FOR (fs::path dir, include_path) { ++count; state.dependencies.add_glob(dir / parameter.value); include_search_glob( @@ -234,7 +234,7 @@ namespace quickbook // Search in each of the include path locations. unsigned count = 0; - BOOST_FOREACH (fs::path full, include_path) { + QUICKBOOK_FOR (fs::path full, include_path) { ++count; full /= path; diff --git a/src/markups.cpp b/src/markups.cpp index df8cd3c..cd13b02 100644 --- a/src/markups.cpp +++ b/src/markups.cpp @@ -11,8 +11,8 @@ #include "markups.hpp" #include #include -#include #include "block_tags.hpp" +#include "for.hpp" #include "phrase_tags.hpp" #include "quickbook.hpp" @@ -67,7 +67,7 @@ namespace quickbook ""}, {phrase_tags::break_mark, "\n", 0}}; - BOOST_FOREACH (markup m, init_markups) { + QUICKBOOK_FOR (markup m, init_markups) { markups[m.tag] = m; } } diff --git a/src/path.cpp b/src/path.cpp index 5abec4e..9c3a070 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -12,8 +12,8 @@ #include "path.hpp" #include #include -#include #include +#include "for.hpp" #include "glob.hpp" #include "include_paths.hpp" #include "state.hpp" @@ -35,7 +35,7 @@ namespace quickbook std::vector parts; - BOOST_FOREACH (fs::path const& part, path) { + QUICKBOOK_FOR (fs::path const& part, path) { if (part.empty() || part == ".") { } else if (part == "..") { diff --git a/src/phrase_element_grammar.cpp b/src/phrase_element_grammar.cpp index aa0b04c..ed33e30 100644 --- a/src/phrase_element_grammar.cpp +++ b/src/phrase_element_grammar.cpp @@ -8,7 +8,6 @@ http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ -#include #include #include #include @@ -16,6 +15,7 @@ #include #include #include "actions.hpp" +#include "for.hpp" #include "grammar_impl.hpp" #include "phrase_tags.hpp" #include "state.hpp" @@ -178,7 +178,7 @@ namespace quickbook cl::eps_p [state.values.entry(ph::arg1, ph::arg2)] >> source_modes [state.values.entry(ph::arg1)]; - BOOST_FOREACH(int tag, source_mode_tags::tags()) { + QUICKBOOK_FOR(int tag, source_mode_tags::tags()) { source_modes.add(source_mode_tags::name(tag), tag); elements.add(source_mode_tags::name(tag), element_info(element_info::phrase, &local.empty, tag)); diff --git a/src/quickbook.cpp b/src/quickbook.cpp index 6c5ebb8..b829c09 100644 --- a/src/quickbook.cpp +++ b/src/quickbook.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -21,6 +20,7 @@ #include "actions.hpp" #include "document_state.hpp" #include "files.hpp" +#include "for.hpp" #include "grammar.hpp" #include "path.hpp" #include "post_process.hpp" @@ -453,7 +453,7 @@ int main(int argc, char* argv[]) unsigned flags = 0; - BOOST_FOREACH (std::string const& flag, flag_names) { + QUICKBOOK_FOR (std::string const& flag, flag_names) { if (flag == "checked") { flags |= quickbook::dependency_tracker::checked; } diff --git a/src/state.cpp b/src/state.cpp index 314f2fc..af57b24 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -9,8 +9,8 @@ http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ #include "state.hpp" -#include #include "document_state.hpp" +#include "for.hpp" #include "grammar.hpp" #include "path.hpp" #include "phrase_tags.hpp" @@ -109,7 +109,7 @@ namespace quickbook { source_mode_info result; - BOOST_FOREACH (source_mode_info const& s, tagged_source_mode_stack) { + QUICKBOOK_FOR (source_mode_info const& s, tagged_source_mode_stack) { result.update(s); } @@ -122,7 +122,7 @@ namespace quickbook result.update(document.section_source_mode()); - BOOST_FOREACH (source_mode_info const& s, tagged_source_mode_stack) { + QUICKBOOK_FOR (source_mode_info const& s, tagged_source_mode_stack) { result.update(s); }