diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f45cde0..b1814723 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,12 +14,12 @@ target_include_directories(cpp-dump INTERFACE $ +``` + +#### Use `FetchContent` + +`CMakeLists.txt` + +```cmake +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Generate compile_commands.json (optional) + +include(FetchContent) + +# Fetch cpp-dump +FetchContent_Declare(cpp-dump + GIT_REPOSITORY https://github.com/philip82148/cpp-dump + GIT_TAG main +) +FetchContent_MakeAvailable(cpp-dump) + +# Link cpp-dump to your app +target_link_libraries(MyApp PRIVATE cpp-dump) +``` + +Then + +```cpp +#include ``` ## Configuration (as needed) -If you want to customize the library, use the `CPP_DUMP_SET_OPTION_GLOBAL()` macro: +If you want to customize the library, you can write the configuration code as follows: + +`custom-cpp-dump.hpp` ```cpp -// You can also write this in a header file ----------------------------------- #ifdef DEBUGGING -#include "path/to/cpp-dump/dump.hpp" +#include "path/to/cpp-dump/cpp-dump.hpp" namespace cp = cpp_dump; +// You can use this in both a header file and a source file, +// but make sure not to use it more than once for the same option. CPP_DUMP_SET_OPTION_GLOBAL(max_line_width, 100); + +// To ensure proper instantiation of templates, +// include these in at least one translation unit where cpp_dump(...) prints each type. +// One way is to write them in a header file and then include it wherever needed. +CPP_DUMP_DEFINE_EXPORT_ENUM(my_enum, my_enum::a, my_enum::b, my_enum::c); +CPP_DUMP_DEFINE_EXPORT_OBJECT(my_class, member1, member2()); +CPP_DUMP_DEFINE_EXPORT_OBJECT_GENERIC(member3, member4()); #else #define cpp_dump(...) +#define CPP_DUMP_SET_OPTION(...) #endif -// You can also write this in a header file ----------------------------------- +``` + +`main.cpp` + +```cpp +#include "path/to/custom-cpp-dump.hpp" int main() { - // To be continued... + cpp_dump(vec | cp::back()); } ``` If you want to configure the library within a function, use `CPP_DUMP_SET_OPTION()` instead. ```cpp -// You can also write this in a header file ----------------------------------- -#ifdef DEBUGGING -#include "path/to/cpp-dump/dump.hpp" -namespace cp = cpp_dump; -#else -#define cpp_dump(...) -#define CPP_DUMP_SET_OPTION(...) -#endif -// You can also write this in a header file ----------------------------------- +#include "path/to/custom-cpp-dump.hpp" -int main() { - CPP_DUMP_SET_OPTION(max_line_width, 100); - - // To be continued... +void func() { + CPP_DUMP_SET_OPTION(print_expr, false); + cpp_dump(vec | cp::back()); + CPP_DUMP_SET_OPTION(print_expr, true); } ``` @@ -1003,7 +1061,7 @@ inline void cpp_dump::write_log(std::string_view output) { ```cpp #ifdef DEFINED_ONLY_IN_LOCAL -#include "./cpp-dump/dump.hpp" +#include "./cpp-dump/cpp-dump.hpp" #define dump(...) cpp_dump(__VA_ARGS__) namespace cp = cpp_dump; CPP_DUMP_SET_OPTION_GLOBAL(max_line_width, 80); diff --git a/cpp-dump.hpp b/cpp-dump.hpp new file mode 100644 index 00000000..83693934 --- /dev/null +++ b/cpp-dump.hpp @@ -0,0 +1,263 @@ +/* + * Copyright (c) 2023 Ryota Sasaki. + * + * This source code is licensed under the MIT license found in the LICENSE file in the root + * directory of this source tree. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "./cpp-dump/hpp/escape_sequence.hpp" +#include "./cpp-dump/hpp/expand_va_macro.hpp" +#include "./cpp-dump/hpp/export_command/export_command.hpp" +#include "./cpp-dump/hpp/export_var/export_var.hpp" +#include "./cpp-dump/hpp/options.hpp" +#include "./cpp-dump/hpp/utility.hpp" + +#define _p_CPP_DUMP_EXPAND_FOR_CPP_DUMP(expr) #expr + +/** + * Print string representations of expressions and results to std::clog or other configurable + * outputs. + * If you want to change the output, define an explicit specialization of cpp_dump::write_log(). + * This macro uses cpp_dump::export_var() internally. + */ +#define cpp_dump(...) \ + cpp_dump::_detail::cpp_dump_macro<_p_CPP_DUMP_VA_SIZE(__VA_ARGS__)>( \ + {__FILE__, __LINE__, __func__}, \ + {_p_CPP_DUMP_EXPAND_VA(_p_CPP_DUMP_EXPAND_FOR_CPP_DUMP, __VA_ARGS__)}, \ + __VA_ARGS__ \ + ) + +/** + * This is deprecated. + * Use cpp_dump() instead. + */ +#define CPP_DUMP(...) \ + _Pragma("message(\"WARNING: Deprecated. Use the lowercase 'cpp_dump()' macro instead.\")") \ + cpp_dump(__VA_ARGS__) + +namespace cpp_dump { + +/** + * cpp_dump() uses this function to print logs. + * Define an explicit specialization with 'void' to customize this function. + */ +template +void write_log(std::string_view output) { + std::clog << output << std::endl; +} + +namespace _detail { + +template +bool _dump_one( + std::string &output, + const std::string &log_label, + bool always_newline_before_expr, + std::string_view expr, + const T &value +) { + const std::string initial_indent(get_last_line_length(log_label), ' '); + const std::string second_indent = initial_indent + " "; + const bool fail_on_newline_in_value = !always_newline_before_expr; + + if (output.length() == 0) { + output = es::reset() + es::log(log_label); + } else { + if (always_newline_before_expr) { + output += es::log(",\n") + initial_indent; + } else { + output += es::log(", "); + } + } + + struct prefix_and_value_str { + std::string prefix; + std::string value_str; + bool value_str_has_newline; + bool over_max_line_width; + }; + + auto make_prefix_and_value_str = [&, fail_on_newline_in_value]( + const std::string &prefix, const std::string &indent + ) -> prefix_and_value_str { + auto last_line_length = get_last_line_length(output + prefix); + + std::string value_str = export_var( + value, + indent, + last_line_length, + 0, + fail_on_newline_in_value, + export_command::default_command + ); + + bool value_str_has_newline = has_newline(value_str); + + bool over_max_line_width = + last_line_length + get_first_line_length(value_str) > options::max_line_width; + + return {prefix, value_str, value_str_has_newline, over_max_line_width}; + }; + + auto append_output = [&](const prefix_and_value_str &pattern) -> void { + output += pattern.prefix + pattern.value_str; + }; + + if (!options::print_expr) { + prefix_and_value_str pattern1 = make_prefix_and_value_str("", initial_indent); + + if (!fail_on_newline_in_value) { + append_output(pattern1); + return true; + } + + if (!(pattern1.value_str_has_newline || pattern1.over_max_line_width)) { + append_output(pattern1); + return true; + } + + if (get_last_line_length(output) <= initial_indent.length()) return false; + + prefix_and_value_str pattern2 = + make_prefix_and_value_str("\n" + initial_indent, initial_indent); + + if (!(pattern2.value_str_has_newline || pattern2.over_max_line_width)) { + append_output(pattern2); + return true; + } + + return false; + } + + auto expr_with_es = es::expression(expr); + + if (fail_on_newline_in_value) { + prefix_and_value_str pattern1a = + make_prefix_and_value_str(expr_with_es + es::log(" => "), initial_indent); + + if (!(pattern1a.value_str_has_newline || pattern1a.over_max_line_width)) { + append_output(pattern1a); + return true; + } + + if (get_last_line_length(output) <= initial_indent.length()) { + prefix_and_value_str pattern1b = make_prefix_and_value_str( + expr_with_es + "\n" + second_indent + es::log("=> "), second_indent + ); + + if (!pattern1b.value_str_has_newline) { + append_output(pattern1b); + return true; + } + + return false; + } + + prefix_and_value_str pattern2a = make_prefix_and_value_str( + "\n" + initial_indent + expr_with_es + es::log(" => "), initial_indent + ); + + if (!(pattern2a.value_str_has_newline || pattern2a.over_max_line_width)) { + append_output(pattern2a); + return true; + } + + prefix_and_value_str pattern2b = make_prefix_and_value_str( + "\n" + initial_indent + expr_with_es + "\n" + second_indent + es::log("=> "), second_indent + ); + + if (!pattern2b.value_str_has_newline) { + append_output(pattern2b); + return true; + } + + return false; + } + + prefix_and_value_str pattern1a = + make_prefix_and_value_str(expr_with_es + es::log(" => "), initial_indent); + + if (!pattern1a.over_max_line_width) { + if (!pattern1a.value_str_has_newline) { + append_output(pattern1a); + return true; + } + + prefix_and_value_str pattern1b = make_prefix_and_value_str( + expr_with_es + "\n" + second_indent + es::log("=> "), second_indent + ); + + if (!pattern1b.value_str_has_newline) { + append_output(pattern1b); + return true; + } + + append_output(pattern1a); + return true; + } + + prefix_and_value_str pattern1b = make_prefix_and_value_str( + expr_with_es + "\n" + second_indent + es::log("=> "), second_indent + ); + + append_output(pattern1b); + return true; +} + +template +bool _dump( + std::string &output, + const std::string &log_label, + bool always_newline_before_expr, + std::initializer_list exprs, + const Args &...args +) { + auto it = exprs.begin(); + return (... && _dump_one(output, log_label, always_newline_before_expr, *it++, args)); +} + +struct _source_location { + std::string_view file_name; + std::size_t line; + std::string_view function_name; +}; + +// function called by cpp_dump() macro +template +void cpp_dump_macro( + _source_location loc, std::initializer_list exprs, const Args &...args +) { + static_assert( + macro_va_size == sizeof...(args), + "The number of expressions passed to cpp_dump(...) does not match the number of actual " + "arguments. Please enclose the expressions that contains commas in parentheses." + ); + + std::string log_label = options::log_label_func + ? options::log_label_func(loc.file_name, loc.line, loc.function_name) + : ""; + + bool exprs_have_newline = + options::print_expr && std::any_of(exprs.begin(), exprs.end(), has_newline); + + std::string output; + if (exprs_have_newline || !_dump(output, log_label, false, exprs, args...)) { + output = ""; + _dump(output, log_label, true, exprs, args...); + } + + write_log(output); +} + +} // namespace _detail + +} // namespace cpp_dump diff --git a/hpp/escape_sequence.hpp b/cpp-dump/hpp/escape_sequence.hpp similarity index 100% rename from hpp/escape_sequence.hpp rename to cpp-dump/hpp/escape_sequence.hpp diff --git a/hpp/expand_va_macro.hpp b/cpp-dump/hpp/expand_va_macro.hpp similarity index 100% rename from hpp/expand_va_macro.hpp rename to cpp-dump/hpp/expand_va_macro.hpp diff --git a/hpp/export_command/export_command.hpp b/cpp-dump/hpp/export_command/export_command.hpp similarity index 100% rename from hpp/export_command/export_command.hpp rename to cpp-dump/hpp/export_command/export_command.hpp diff --git a/hpp/export_command/skip_container.hpp b/cpp-dump/hpp/export_command/skip_container.hpp similarity index 100% rename from hpp/export_command/skip_container.hpp rename to cpp-dump/hpp/export_command/skip_container.hpp diff --git a/hpp/export_var/export_arithmetic.hpp b/cpp-dump/hpp/export_var/export_arithmetic.hpp similarity index 100% rename from hpp/export_var/export_arithmetic.hpp rename to cpp-dump/hpp/export_var/export_arithmetic.hpp diff --git a/hpp/export_var/export_asterisk.hpp b/cpp-dump/hpp/export_var/export_asterisk.hpp similarity index 100% rename from hpp/export_var/export_asterisk.hpp rename to cpp-dump/hpp/export_var/export_asterisk.hpp diff --git a/hpp/export_var/export_container.hpp b/cpp-dump/hpp/export_var/export_container.hpp similarity index 100% rename from hpp/export_var/export_container.hpp rename to cpp-dump/hpp/export_var/export_container.hpp diff --git a/hpp/export_var/export_enum.hpp b/cpp-dump/hpp/export_var/export_enum.hpp similarity index 100% rename from hpp/export_var/export_enum.hpp rename to cpp-dump/hpp/export_var/export_enum.hpp diff --git a/hpp/export_var/export_exception.hpp b/cpp-dump/hpp/export_var/export_exception.hpp similarity index 100% rename from hpp/export_var/export_exception.hpp rename to cpp-dump/hpp/export_var/export_exception.hpp diff --git a/hpp/export_var/export_map.hpp b/cpp-dump/hpp/export_var/export_map.hpp similarity index 100% rename from hpp/export_var/export_map.hpp rename to cpp-dump/hpp/export_var/export_map.hpp diff --git a/hpp/export_var/export_object.hpp b/cpp-dump/hpp/export_var/export_object.hpp similarity index 100% rename from hpp/export_var/export_object.hpp rename to cpp-dump/hpp/export_var/export_object.hpp diff --git a/hpp/export_var/export_object_common.hpp b/cpp-dump/hpp/export_var/export_object_common.hpp similarity index 100% rename from hpp/export_var/export_object_common.hpp rename to cpp-dump/hpp/export_var/export_object_common.hpp diff --git a/hpp/export_var/export_object_generic.hpp b/cpp-dump/hpp/export_var/export_object_generic.hpp similarity index 100% rename from hpp/export_var/export_object_generic.hpp rename to cpp-dump/hpp/export_var/export_object_generic.hpp diff --git a/hpp/export_var/export_ostream.hpp b/cpp-dump/hpp/export_var/export_ostream.hpp similarity index 100% rename from hpp/export_var/export_ostream.hpp rename to cpp-dump/hpp/export_var/export_ostream.hpp diff --git a/hpp/export_var/export_other/export_es_value_t.hpp b/cpp-dump/hpp/export_var/export_other/export_es_value_t.hpp similarity index 100% rename from hpp/export_var/export_other/export_es_value_t.hpp rename to cpp-dump/hpp/export_var/export_other/export_es_value_t.hpp diff --git a/hpp/export_var/export_other/export_optional.hpp b/cpp-dump/hpp/export_var/export_other/export_optional.hpp similarity index 100% rename from hpp/export_var/export_other/export_optional.hpp rename to cpp-dump/hpp/export_var/export_other/export_optional.hpp diff --git a/hpp/export_var/export_other/export_other.hpp b/cpp-dump/hpp/export_var/export_other/export_other.hpp similarity index 100% rename from hpp/export_var/export_other/export_other.hpp rename to cpp-dump/hpp/export_var/export_other/export_other.hpp diff --git a/hpp/export_var/export_other/export_other_object.hpp b/cpp-dump/hpp/export_var/export_other/export_other_object.hpp similarity index 100% rename from hpp/export_var/export_other/export_other_object.hpp rename to cpp-dump/hpp/export_var/export_other/export_other_object.hpp diff --git a/hpp/export_var/export_other/export_type_info.hpp b/cpp-dump/hpp/export_var/export_other/export_type_info.hpp similarity index 100% rename from hpp/export_var/export_other/export_type_info.hpp rename to cpp-dump/hpp/export_var/export_other/export_type_info.hpp diff --git a/hpp/export_var/export_pointer.hpp b/cpp-dump/hpp/export_var/export_pointer.hpp similarity index 100% rename from hpp/export_var/export_pointer.hpp rename to cpp-dump/hpp/export_var/export_pointer.hpp diff --git a/hpp/export_var/export_set.hpp b/cpp-dump/hpp/export_var/export_set.hpp similarity index 100% rename from hpp/export_var/export_set.hpp rename to cpp-dump/hpp/export_var/export_set.hpp diff --git a/hpp/export_var/export_string.hpp b/cpp-dump/hpp/export_var/export_string.hpp similarity index 100% rename from hpp/export_var/export_string.hpp rename to cpp-dump/hpp/export_var/export_string.hpp diff --git a/hpp/export_var/export_tuple.hpp b/cpp-dump/hpp/export_var/export_tuple.hpp similarity index 100% rename from hpp/export_var/export_tuple.hpp rename to cpp-dump/hpp/export_var/export_tuple.hpp diff --git a/hpp/export_var/export_unsupported.hpp b/cpp-dump/hpp/export_var/export_unsupported.hpp similarity index 100% rename from hpp/export_var/export_unsupported.hpp rename to cpp-dump/hpp/export_var/export_unsupported.hpp diff --git a/hpp/export_var/export_var.hpp b/cpp-dump/hpp/export_var/export_var.hpp similarity index 100% rename from hpp/export_var/export_var.hpp rename to cpp-dump/hpp/export_var/export_var.hpp diff --git a/hpp/export_var/export_var_fwd.hpp b/cpp-dump/hpp/export_var/export_var_fwd.hpp similarity index 100% rename from hpp/export_var/export_var_fwd.hpp rename to cpp-dump/hpp/export_var/export_var_fwd.hpp diff --git a/hpp/export_var/export_xixo.hpp b/cpp-dump/hpp/export_var/export_xixo.hpp similarity index 100% rename from hpp/export_var/export_xixo.hpp rename to cpp-dump/hpp/export_var/export_xixo.hpp diff --git a/hpp/iterable.hpp b/cpp-dump/hpp/iterable.hpp similarity index 100% rename from hpp/iterable.hpp rename to cpp-dump/hpp/iterable.hpp diff --git a/hpp/log_label.hpp b/cpp-dump/hpp/log_label.hpp similarity index 100% rename from hpp/log_label.hpp rename to cpp-dump/hpp/log_label.hpp diff --git a/hpp/options.hpp b/cpp-dump/hpp/options.hpp similarity index 100% rename from hpp/options.hpp rename to cpp-dump/hpp/options.hpp diff --git a/hpp/type_check.hpp b/cpp-dump/hpp/type_check.hpp similarity index 100% rename from hpp/type_check.hpp rename to cpp-dump/hpp/type_check.hpp diff --git a/hpp/utility.hpp b/cpp-dump/hpp/utility.hpp similarity index 100% rename from hpp/utility.hpp rename to cpp-dump/hpp/utility.hpp diff --git a/dump.hpp b/dump.hpp index cd0a58a4..c7d2a7bf 100644 --- a/dump.hpp +++ b/dump.hpp @@ -1,263 +1,6 @@ -/* - * Copyright (c) 2023 Ryota Sasaki. - * - * This source code is licensed under the MIT license found in the LICENSE file in the root - * directory of this source tree. - */ - +// See https://github.com/philip82148/cpp-dump/pull/100 for details of this file. #pragma once - -#include -#include -#include -#include -#include -#include - -#include "hpp/escape_sequence.hpp" -#include "hpp/expand_va_macro.hpp" -#include "hpp/export_command/export_command.hpp" -#include "hpp/export_var/export_var.hpp" -#include "hpp/options.hpp" -#include "hpp/utility.hpp" - -#define _p_CPP_DUMP_EXPAND_FOR_CPP_DUMP(expr) #expr - -/** - * Print string representations of expressions and results to std::clog or other configurable - * outputs. - * If you want to change the output, define an explicit specialization of cpp_dump::write_log(). - * This macro uses cpp_dump::export_var() internally. - */ -#define cpp_dump(...) \ - cpp_dump::_detail::cpp_dump_macro<_p_CPP_DUMP_VA_SIZE(__VA_ARGS__)>( \ - {__FILE__, __LINE__, __func__}, \ - {_p_CPP_DUMP_EXPAND_VA(_p_CPP_DUMP_EXPAND_FOR_CPP_DUMP, __VA_ARGS__)}, \ - __VA_ARGS__ \ - ) - -/** - * This is deprecated. - * Use cpp_dump() instead. - */ -#define CPP_DUMP(...) \ - _Pragma("message(\"WARNING: Deprecated. Use the lowercase 'cpp_dump()' macro instead.\")") \ - cpp_dump(__VA_ARGS__) - -namespace cpp_dump { - -/** - * cpp_dump() uses this function to print logs. - * Define an explicit specialization with 'void' to customize this function. - */ -template -void write_log(std::string_view output) { - std::clog << output << std::endl; -} - -namespace _detail { - -template -bool _dump_one( - std::string &output, - const std::string &log_label, - bool always_newline_before_expr, - std::string_view expr, - const T &value -) { - const std::string initial_indent(get_last_line_length(log_label), ' '); - const std::string second_indent = initial_indent + " "; - const bool fail_on_newline_in_value = !always_newline_before_expr; - - if (output.length() == 0) { - output = es::reset() + es::log(log_label); - } else { - if (always_newline_before_expr) { - output += es::log(",\n") + initial_indent; - } else { - output += es::log(", "); - } - } - - struct prefix_and_value_str { - std::string prefix; - std::string value_str; - bool value_str_has_newline; - bool over_max_line_width; - }; - - auto make_prefix_and_value_str = [&, fail_on_newline_in_value]( - const std::string &prefix, const std::string &indent - ) -> prefix_and_value_str { - auto last_line_length = get_last_line_length(output + prefix); - - std::string value_str = export_var( - value, - indent, - last_line_length, - 0, - fail_on_newline_in_value, - export_command::default_command - ); - - bool value_str_has_newline = has_newline(value_str); - - bool over_max_line_width = - last_line_length + get_first_line_length(value_str) > options::max_line_width; - - return {prefix, value_str, value_str_has_newline, over_max_line_width}; - }; - - auto append_output = [&](const prefix_and_value_str &pattern) -> void { - output += pattern.prefix + pattern.value_str; - }; - - if (!options::print_expr) { - prefix_and_value_str pattern1 = make_prefix_and_value_str("", initial_indent); - - if (!fail_on_newline_in_value) { - append_output(pattern1); - return true; - } - - if (!(pattern1.value_str_has_newline || pattern1.over_max_line_width)) { - append_output(pattern1); - return true; - } - - if (get_last_line_length(output) <= initial_indent.length()) return false; - - prefix_and_value_str pattern2 = - make_prefix_and_value_str("\n" + initial_indent, initial_indent); - - if (!(pattern2.value_str_has_newline || pattern2.over_max_line_width)) { - append_output(pattern2); - return true; - } - - return false; - } - - auto expr_with_es = es::expression(expr); - - if (fail_on_newline_in_value) { - prefix_and_value_str pattern1a = - make_prefix_and_value_str(expr_with_es + es::log(" => "), initial_indent); - - if (!(pattern1a.value_str_has_newline || pattern1a.over_max_line_width)) { - append_output(pattern1a); - return true; - } - - if (get_last_line_length(output) <= initial_indent.length()) { - prefix_and_value_str pattern1b = make_prefix_and_value_str( - expr_with_es + "\n" + second_indent + es::log("=> "), second_indent - ); - - if (!pattern1b.value_str_has_newline) { - append_output(pattern1b); - return true; - } - - return false; - } - - prefix_and_value_str pattern2a = make_prefix_and_value_str( - "\n" + initial_indent + expr_with_es + es::log(" => "), initial_indent - ); - - if (!(pattern2a.value_str_has_newline || pattern2a.over_max_line_width)) { - append_output(pattern2a); - return true; - } - - prefix_and_value_str pattern2b = make_prefix_and_value_str( - "\n" + initial_indent + expr_with_es + "\n" + second_indent + es::log("=> "), second_indent - ); - - if (!pattern2b.value_str_has_newline) { - append_output(pattern2b); - return true; - } - - return false; - } - - prefix_and_value_str pattern1a = - make_prefix_and_value_str(expr_with_es + es::log(" => "), initial_indent); - - if (!pattern1a.over_max_line_width) { - if (!pattern1a.value_str_has_newline) { - append_output(pattern1a); - return true; - } - - prefix_and_value_str pattern1b = make_prefix_and_value_str( - expr_with_es + "\n" + second_indent + es::log("=> "), second_indent - ); - - if (!pattern1b.value_str_has_newline) { - append_output(pattern1b); - return true; - } - - append_output(pattern1a); - return true; - } - - prefix_and_value_str pattern1b = make_prefix_and_value_str( - expr_with_es + "\n" + second_indent + es::log("=> "), second_indent - ); - - append_output(pattern1b); - return true; -} - -template -bool _dump( - std::string &output, - const std::string &log_label, - bool always_newline_before_expr, - std::initializer_list exprs, - const Args &...args -) { - auto it = exprs.begin(); - return (... && _dump_one(output, log_label, always_newline_before_expr, *it++, args)); -} - -struct _source_location { - std::string_view file_name; - std::size_t line; - std::string_view function_name; -}; - -// function called by cpp_dump() macro -template -void cpp_dump_macro( - _source_location loc, std::initializer_list exprs, const Args &...args -) { - static_assert( - macro_va_size == sizeof...(args), - "The number of expressions passed to cpp_dump(...) does not match the number of actual " - "arguments. Please enclose the expressions that contains commas in parentheses." - ); - - std::string log_label = options::log_label_func - ? options::log_label_func(loc.file_name, loc.line, loc.function_name) - : ""; - - bool exprs_have_newline = - options::print_expr && std::any_of(exprs.begin(), exprs.end(), has_newline); - - std::string output; - if (exprs_have_newline || !_dump(output, log_label, false, exprs, args...)) { - output = ""; - _dump(output, log_label, true, exprs, args...); - } - - write_log(output); -} - -} // namespace _detail - -} // namespace cpp_dump +#pragma message( \ + "WARNING: The 'dump.hpp' header is deprecated. Include the 'cpp-dump.hpp' header instead." \ +) +#include "./cpp-dump.hpp" diff --git a/readme/auto-indent.cpp b/readme/auto-indent.cpp index 6bea2a8d..8620f876 100644 --- a/readme/auto-indent.cpp +++ b/readme/auto-indent.cpp @@ -2,7 +2,7 @@ #include #include -#include "../dump.hpp" +#include "../cpp-dump.hpp" int main() { std::clog << std::endl; diff --git a/readme/customizable-colors.cpp b/readme/customizable-colors.cpp index 083b095e..e5d42136 100644 --- a/readme/customizable-colors.cpp +++ b/readme/customizable-colors.cpp @@ -12,7 +12,7 @@ #include #include -#include "../dump.hpp" +#include "../cpp-dump.hpp" namespace cp = cpp_dump; int main() { diff --git a/readme/customize-dump.cpp b/readme/customize-dump.cpp index f60dcb5b..5cdbeba2 100644 --- a/readme/customize-dump.cpp +++ b/readme/customize-dump.cpp @@ -3,7 +3,7 @@ #include #include -#include "../dump.hpp" +#include "../cpp-dump.hpp" namespace cp = cpp_dump; void my_func() { diff --git a/readme/formatting-with-manipulators.cpp b/readme/formatting-with-manipulators.cpp index 0fdc482c..d9f10ed1 100644 --- a/readme/formatting-with-manipulators.cpp +++ b/readme/formatting-with-manipulators.cpp @@ -2,7 +2,7 @@ #include #include -#include "../dump.hpp" +#include "../cpp-dump.hpp" namespace cp = cpp_dump; int main() { diff --git a/readme/introduction.cpp b/readme/introduction.cpp index 5287d4fd..8be1c866 100644 --- a/readme/introduction.cpp +++ b/readme/introduction.cpp @@ -1,7 +1,7 @@ #include #include -#include "../dump.hpp" +#include "../cpp-dump.hpp" int main() { std::clog << std::endl; diff --git a/readme/no-es.cpp b/readme/no-es.cpp index 651fca4f..c4eb7624 100644 --- a/readme/no-es.cpp +++ b/readme/no-es.cpp @@ -12,7 +12,7 @@ #include #include -#include "../dump.hpp" +#include "../cpp-dump.hpp" namespace cp = cpp_dump; int main() { diff --git a/readme/supports-various-types.cpp b/readme/supports-various-types.cpp index 03ebf74f..eda8806f 100644 --- a/readme/supports-various-types.cpp +++ b/readme/supports-various-types.cpp @@ -12,7 +12,7 @@ #include #include -#include "../dump.hpp" +#include "../cpp-dump.hpp" int main() { int my_int = 15; diff --git a/readme/user-defined-class.cpp b/readme/user-defined-class.cpp index b9b1502c..f4e243cb 100644 --- a/readme/user-defined-class.cpp +++ b/readme/user-defined-class.cpp @@ -1,6 +1,6 @@ #include -#include "../dump.hpp" +#include "../cpp-dump.hpp" struct class_A { int i; diff --git a/readme/user-defined-class2.cpp b/readme/user-defined-class2.cpp index 268e5363..43cfebb7 100644 --- a/readme/user-defined-class2.cpp +++ b/readme/user-defined-class2.cpp @@ -1,6 +1,6 @@ #include -#include "../dump.hpp" +#include "../cpp-dump.hpp" CPP_DUMP_DEFINE_EXPORT_OBJECT_GENERIC(i, str()); diff --git a/readme/user-defined-class3.cpp b/readme/user-defined-class3.cpp index d5d7a386..db50dde8 100644 --- a/readme/user-defined-class3.cpp +++ b/readme/user-defined-class3.cpp @@ -1,6 +1,6 @@ #include -#include "../dump.hpp" +#include "../cpp-dump.hpp" struct class_A { int i; diff --git a/readme/user-defined-enum.cpp b/readme/user-defined-enum.cpp index 1f2638ac..7f2e8ad1 100644 --- a/readme/user-defined-enum.cpp +++ b/readme/user-defined-enum.cpp @@ -1,6 +1,6 @@ #include -#include "../dump.hpp" +#include "../cpp-dump.hpp" enum class enum_A { a, b, c }; CPP_DUMP_DEFINE_EXPORT_ENUM(enum_A, enum_A::a, enum_A::b, enum_A::c); diff --git a/test/color_non_variable_test.cpp b/test/color_non_variable_test.cpp index 7848a491..e3d1b365 100644 --- a/test/color_non_variable_test.cpp +++ b/test/color_non_variable_test.cpp @@ -1,4 +1,4 @@ -#include "../dump.hpp" +#include "../cpp-dump.hpp" namespace cp = cpp_dump; #include diff --git a/test/color_rtti_test.cpp b/test/color_rtti_test.cpp index 7be2bc07..3835a8ae 100644 --- a/test/color_rtti_test.cpp +++ b/test/color_rtti_test.cpp @@ -1,6 +1,6 @@ #include -#include "../dump.hpp" +#include "../cpp-dump.hpp" namespace cp = cpp_dump; diff --git a/test/color_std_version_test.cpp b/test/color_std_version_test.cpp index d8829f4e..21b02a52 100644 --- a/test/color_std_version_test.cpp +++ b/test/color_std_version_test.cpp @@ -10,7 +10,7 @@ struct source_location { #endif #endif -#include "../dump.hpp" +#include "../cpp-dump.hpp" // These are often used to write code faster in competitive programming. // This is the test for it. diff --git a/test/dump_indent_test.cpp b/test/dump_indent_test.cpp index 7b3bacc5..0337d008 100644 --- a/test/dump_indent_test.cpp +++ b/test/dump_indent_test.cpp @@ -1,4 +1,4 @@ -#include "../dump.hpp" +#include "../cpp-dump.hpp" namespace cp = cpp_dump; #ifdef USE_BITS_STDC diff --git a/test/dump_non_variable_test.cpp b/test/dump_non_variable_test.cpp index 451ccccf..8018efab 100644 --- a/test/dump_non_variable_test.cpp +++ b/test/dump_non_variable_test.cpp @@ -1,4 +1,4 @@ -#include "../dump.hpp" +#include "../cpp-dump.hpp" namespace cp = cpp_dump; #ifdef USE_BITS_STDC diff --git a/test/dump_variable_test.cpp b/test/dump_variable_test.cpp index e35d6a8a..dff1a5aa 100644 --- a/test/dump_variable_test.cpp +++ b/test/dump_variable_test.cpp @@ -3,7 +3,7 @@ #include #include // -#include "../dump.hpp" +#include "../cpp-dump.hpp" // These are often used to write code faster in competitive programming. // This is the test for it. diff --git a/test/log_label_test.cpp b/test/log_label_test.cpp index dba5aa73..0abc16c6 100644 --- a/test/log_label_test.cpp +++ b/test/log_label_test.cpp @@ -3,7 +3,7 @@ #include #include -#include "../dump.hpp" +#include "../cpp-dump.hpp" // using namespace std; diff --git a/test/odr_test.cpp b/test/odr_test.cpp index 4ff38fd0..fbb84ef8 100644 --- a/test/odr_test.cpp +++ b/test/odr_test.cpp @@ -1,5 +1,5 @@ #include "./odr_test.hpp" -#include "../dump.hpp" +#include "../cpp-dump.hpp" void odr_test() { cpp_dump(class_a(), class_b(), enum_a::s); } diff --git a/test/odr_test.hpp b/test/odr_test.hpp index 0f7aadb3..03596cd7 100644 --- a/test/odr_test.hpp +++ b/test/odr_test.hpp @@ -1,6 +1,6 @@ #include -#include "../dump.hpp" +#include "../cpp-dump.hpp" enum class enum_a { s, k, l }; diff --git a/test/static_test.cpp b/test/static_test.cpp index 0253026c..1da1bd6d 100644 --- a/test/static_test.cpp +++ b/test/static_test.cpp @@ -1,4 +1,4 @@ -#include "../dump.hpp" +#include "../cpp-dump.hpp" #include "./odr_test.hpp" template