Skip to content

Commit

Permalink
just upgrade GoogleTest and go to C++14
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb committed Nov 15, 2023
1 parent 87f9bc2 commit e55e2b2
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 20 deletions.
11 changes: 6 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ endif()

project(lightgbm LANGUAGES C CXX)

if(BUILD_CPP_TEST)
set(CMAKE_CXX_STANDARD 14)
else()
set(CMAKE_CXX_STANDARD 11)
endif()

list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules")

#-- Sanitizer
Expand Down Expand Up @@ -327,11 +333,6 @@ if(${MM_MALLOC})
endif()

if(UNIX OR MINGW OR CYGWIN)
if(BUILD_CPP_TEST)
set(CMAKE_CXX_STANDARD 20)
else()
set(CMAKE_CXX_STANDARD 11)
endif()
set(
CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -pthread -Wextra -Wall -Wno-ignored-attributes -Wno-unknown-pragmas -Wno-return-type"
Expand Down
12 changes: 5 additions & 7 deletions include/LightGBM/utils/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1197,11 +1197,9 @@ inline static std::vector<T> StringToArray(const std::string& str, char delimite
* This safety check serves to prevent incorrect internal API usage.
* Correct usage will never incur in this problem:
* - The received buffer size shall be sufficient at all times for the input format string and value.
* /Users/jlamb/repos/LightGBM/include/LightGBM/utils/common.h:1203:35: in 'constexpr' expansion of 'fmt::v8::basic_format_string<char, const unsigned int&>(format)'
* /Users/jlamb/repos/LightGBM/include/LightGBM/utils/common.h:1203:35: error: 'format' is not a constant expression
*/
template <typename T>
inline static void format_to_buf(char* buffer, const size_t buf_len, fmt::format_string<T> format, const T value) {
inline static void format_to_buf(char* buffer, const size_t buf_len, const char* format, const T value) {
auto result = fmt::format_to_n(buffer, buf_len, format, value);
if (result.size >= buf_len) {
Log::Fatal("Numerical conversion failed. Buffer is too small.");
Expand All @@ -1212,29 +1210,29 @@ inline static void format_to_buf(char* buffer, const size_t buf_len, fmt::format
template<typename T, bool is_float, bool high_precision>
struct __TToStringHelper {
void operator()(T value, char* buffer, size_t buf_len) const {
format_to_buf(buffer, buf_len, fmt::format_string<T>("{}"), value);
format_to_buf(buffer, buf_len, "{}", value);
}
};

template<typename T>
struct __TToStringHelper<T, true, false> {
void operator()(T value, char* buffer, size_t buf_len) const {
format_to_buf(buffer, buf_len, fmt::format_string<T>("{:g}"), value);
format_to_buf(buffer, buf_len, "{:g}", value);
}
};

template<typename T>
struct __TToStringHelper<T, true, true> {
void operator()(T value, char* buffer, size_t buf_len) const {
format_to_buf(buffer, buf_len, fmt::format_string<T>("{:.17g}"), value);
format_to_buf(buffer, buf_len, "{:.17g}", value);
}
};

/*!
* Converts an array to a string with with values separated by the space character.
* This method replaces Common's ``ArrayToString`` and ``ArrayToStringFast`` functionality
* and is locale-independent.
*
*
* \note If ``high_precision_output`` is set to true,
* floating point values are output with more digits of precision.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/io/dense_bin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ class DenseBin : public Bin {
#endif
std::vector<uint8_t> buf_;

DenseBin(const DenseBin& other)
DenseBin<VAL_T, IS_4BIT>(const DenseBin<VAL_T, IS_4BIT>& other)
: num_data_(other.num_data_), data_(other.data_) {}
};

Expand Down
5 changes: 1 addition & 4 deletions src/io/multi_val_dense_bin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,7 @@ class MultiValDenseBin : public MultiValBin {
std::vector<uint32_t> offsets_;
std::vector<VAL_T, Common::AlignmentAllocator<VAL_T, 32>> data_;

// https://oleksandrkvl.github.io/2021/04/02/cpp-20-overview.html
// https://github.com/PixarAnimationStudios/OpenUSD/issues/2183
// https://github.com/PixarAnimationStudios/OpenUSD/pull/2242/files
MultiValDenseBin(const MultiValDenseBin& other)
MultiValDenseBin<VAL_T>(const MultiValDenseBin<VAL_T>& other)
: num_data_(other.num_data_), num_bin_(other.num_bin_), num_feature_(other.num_feature_),
offsets_(other.offsets_), data_(other.data_) {
}
Expand Down
4 changes: 2 additions & 2 deletions src/io/multi_val_sparse_bin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ class MultiValSparseBin : public MultiValBin {
std::vector<INDEX_T> t_size_;
std::vector<uint32_t> offsets_;

MultiValSparseBin(
const MultiValSparseBin& other)
MultiValSparseBin<INDEX_T, VAL_T>(
const MultiValSparseBin<INDEX_T, VAL_T>& other)
: num_data_(other.num_data_),
num_bin_(other.num_bin_),
estimate_element_per_row_(other.estimate_element_per_row_),
Expand Down
2 changes: 1 addition & 1 deletion src/io/sparse_bin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ class SparseBin : public Bin {

SparseBin<VAL_T>* Clone() override;

SparseBin(const SparseBin& other)
SparseBin<VAL_T>(const SparseBin<VAL_T>& other)
: num_data_(other.num_data_),
deltas_(other.deltas_),
vals_(other.vals_),
Expand Down

0 comments on commit e55e2b2

Please sign in to comment.