Skip to content

Commit 844bce3

Browse files
committed
Fix MSVC 2012 compatibility issues in zlayout.cpp
- Add missing #include <chrono> for std::chrono functionality - Add missing #include <cstdio> for sprintf function - Add missing #include <cstdlib> for std::malloc/std::free functions - Replace std::to_string with compatible int_to_string helper for MSVC 2012 - Move helper function to anonymous namespace for better encapsulation - Ensures compatibility with Windows MSVC 2012+ as specified in requirements
1 parent d696b2e commit 844bce3

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/zlayout.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
#include <zlayout/zlayout.hpp>
77
#include <iostream>
88
#include <stdexcept>
9+
#include <chrono>
10+
#include <algorithm>
11+
#include <string>
12+
#include <cstdio>
13+
#include <cstdlib>
914

1015
#ifdef ZLAYOUT_OPENMP
1116
#include <omp.h>
@@ -116,16 +121,29 @@ struct SystemInfo {
116121
size_t max_threads;
117122
};
118123

124+
// Helper function for MSVC 2012 compatibility
125+
namespace {
126+
std::string int_to_string(int value) {
127+
#if defined(_MSC_VER) && _MSC_VER < 1800 // MSVC 2012 and earlier
128+
char buffer[32];
129+
sprintf(buffer, "%d", value);
130+
return std::string(buffer);
131+
#else
132+
return std::to_string(value);
133+
#endif
134+
}
135+
}
136+
119137
SystemInfo get_system_info() {
120138
SystemInfo info;
121139

122140
// Compiler information
123141
#ifdef __GNUC__
124-
info.compiler = "GCC " + std::to_string(__GNUC__) + "." + std::to_string(__GNUC_MINOR__);
142+
info.compiler = "GCC " + int_to_string(__GNUC__) + "." + int_to_string(__GNUC_MINOR__);
125143
#elif defined(__clang__)
126-
info.compiler = "Clang " + std::to_string(__clang_major__) + "." + std::to_string(__clang_minor__);
144+
info.compiler = "Clang " + int_to_string(__clang_major__) + "." + int_to_string(__clang_minor__);
127145
#elif defined(_MSC_VER)
128-
info.compiler = "MSVC " + std::to_string(_MSC_VER);
146+
info.compiler = "MSVC " + int_to_string(_MSC_VER);
129147
#else
130148
info.compiler = "Unknown compiler";
131149
#endif

0 commit comments

Comments
 (0)