Skip to content

Commit f2e3722

Browse files
committed
Added FMT_IMPORT_STD feature macro
1 parent 5eb68c0 commit f2e3722

14 files changed

+130
-91
lines changed

include/fmt/args.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
#ifndef FMT_ARGS_H_
99
#define FMT_ARGS_H_
1010

11-
#include <functional> // std::reference_wrapper
12-
#include <memory> // std::unique_ptr
13-
#include <vector>
11+
#ifndef FMT_IMPORT_STD
12+
# include <functional> // std::reference_wrapper
13+
# include <memory> // std::unique_ptr
14+
# include <vector>
15+
#endif
1416

1517
#include "format.h" // std_string_view
1618

include/fmt/base.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@
1212
#include <stdio.h> // FILE
1313
#include <string.h> // strlen
1414

15+
#ifndef FMT_IMPORT_STD
1516
// <cstddef> is also included transitively from <type_traits>.
16-
#include <cstddef> // std::byte
17-
#include <type_traits> // std::enable_if
17+
# include <cstddef> // std::byte
18+
# include <type_traits> // std::enable_if
19+
#else
20+
import std;
21+
#endif
1822

1923
// The fmt library version in the form major * 10000 + minor * 100 + patch.
2024
#define FMT_VERSION 100202

include/fmt/chrono.h

+11-9
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88
#ifndef FMT_CHRONO_H_
99
#define FMT_CHRONO_H_
1010

11-
#include <algorithm>
12-
#include <chrono>
13-
#include <cmath> // std::isfinite
14-
#include <cstring> // std::memcpy
15-
#include <ctime>
16-
#include <iterator>
17-
#include <locale>
18-
#include <ostream>
19-
#include <type_traits>
11+
#ifndef FMT_IMPORT_STD
12+
# include <algorithm>
13+
# include <chrono>
14+
# include <cmath> // std::isfinite
15+
# include <cstring> // std::memcpy
16+
# include <ctime>
17+
# include <iterator>
18+
# include <locale>
19+
# include <ostream>
20+
# include <type_traits>
21+
#endif
2022

2123
#include "format.h"
2224

include/fmt/compile.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
#ifndef FMT_COMPILE_H_
99
#define FMT_COMPILE_H_
1010

11-
#include <iterator> // std::back_inserter
11+
#ifndef FMT_IMPORT_STD
12+
# include <iterator> // std::back_inserter
13+
#endif
1214

1315
#include "format.h"
1416

include/fmt/format-inl.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
#ifndef FMT_FORMAT_INL_H_
99
#define FMT_FORMAT_INL_H_
1010

11-
#include <algorithm>
11+
#ifndef FMT_IMPORT_STD
12+
# include <algorithm>
13+
# include <climits>
14+
# include <cmath>
15+
# include <exception>
16+
#endif
1217
#include <cerrno> // errno
13-
#include <climits>
14-
#include <cmath>
15-
#include <exception>
1618

17-
#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
19+
#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) && !defined(FMT_IMPORT_STD)
1820
# include <locale>
1921
#endif
2022

include/fmt/format.h

+16-12
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,34 @@
3838
# define FMT_REMOVE_TRANSITIVE_INCLUDES
3939
#endif
4040

41-
#include <cmath> // std::signbit
42-
#include <cstdint> // uint32_t
43-
#include <cstring> // std::memcpy
44-
#include <initializer_list> // std::initializer_list
45-
#include <limits> // std::numeric_limits
46-
#if defined(__GLIBCXX__) && !defined(_GLIBCXX_USE_DUAL_ABI)
41+
#ifndef FMT_IMPORT_STD
42+
# include <cmath> // std::signbit
43+
# include <cstdint> // uint32_t
44+
# include <cstring> // std::memcpy
45+
# include <initializer_list> // std::initializer_list
46+
# include <limits> // std::numeric_limits
47+
# if defined(__GLIBCXX__) && !defined(_GLIBCXX_USE_DUAL_ABI)
4748
// Workaround for pre gcc 5 libstdc++.
48-
# include <memory> // std::allocator_traits
49+
# include <memory> // std::allocator_traits
50+
# endif
51+
# include <stdexcept> // std::runtime_error
52+
# include <string> // std::string
53+
# include <system_error> // std::system_error
4954
#endif
50-
#include <stdexcept> // std::runtime_error
51-
#include <string> // std::string
52-
#include <system_error> // std::system_error
5355

5456
#include "base.h"
5557

5658
// Checking FMT_CPLUSPLUS for warning suppression in MSVC.
57-
#if FMT_HAS_INCLUDE(<bit>) && FMT_CPLUSPLUS > 201703L
59+
#if FMT_HAS_INCLUDE(<bit>) && FMT_CPLUSPLUS > 201703L && !defined(FMT_IMPORT_STD)
5860
# include <bit> // std::bit_cast
5961
#endif
6062

6163
// libc++ supports string_view in pre-c++17.
6264
#if FMT_HAS_INCLUDE(<string_view>) && \
6365
(FMT_CPLUSPLUS >= 201703L || defined(_LIBCPP_VERSION))
64-
# include <string_view>
66+
# ifndef FMT_IMPORT_STD
67+
# include <string_view>
68+
# endif
6569
# define FMT_USE_STRING_VIEW
6670
#endif
6771

include/fmt/os.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
#define FMT_OS_H_
1010

1111
#include <cerrno>
12-
#include <cstddef>
13-
#include <cstdio>
14-
#include <system_error> // std::system_error
12+
#ifndef FMT_IMPORT_STD
13+
# include <cstddef>
14+
# include <cstdio>
15+
# include <system_error> // std::system_error
16+
#endif
1517

1618
#include "format.h"
1719

include/fmt/ostream.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
#ifndef FMT_OSTREAM_H_
99
#define FMT_OSTREAM_H_
1010

11-
#include <fstream> // std::filebuf
11+
#ifndef FMT_IMPORT_STD
12+
# include <fstream> // std::filebuf
13+
#endif
1214

1315
#ifdef _WIN32
1416
# ifdef __GLIBCXX__

include/fmt/printf.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
#ifndef FMT_PRINTF_H_
99
#define FMT_PRINTF_H_
1010

11-
#include <algorithm> // std::max
12-
#include <limits> // std::numeric_limits
11+
#ifndef FMT_IMPORT_STD
12+
# include <algorithm> // std::max
13+
# include <limits> // std::numeric_limits
14+
#endif
1315

1416
#include "format.h"
1517

include/fmt/ranges.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
#ifndef FMT_RANGES_H_
99
#define FMT_RANGES_H_
1010

11-
#include <initializer_list>
12-
#include <iterator>
13-
#include <tuple>
14-
#include <type_traits>
11+
#ifndef FMT_IMPORT_STD
12+
# include <initializer_list>
13+
# include <iterator>
14+
# include <tuple>
15+
# include <type_traits>
16+
#endif
1517

1618
#include "format.h"
1719

include/fmt/std.h

+20-16
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@
88
#ifndef FMT_STD_H_
99
#define FMT_STD_H_
1010

11-
#include <atomic>
12-
#include <bitset>
13-
#include <complex>
14-
#include <cstdlib>
15-
#include <exception>
16-
#include <memory>
17-
#include <thread>
18-
#include <type_traits>
19-
#include <typeinfo>
20-
#include <utility>
21-
#include <vector>
11+
#ifndef FMT_IMPORT_STD
12+
# include <atomic>
13+
# include <bitset>
14+
# include <complex>
15+
# include <cstdlib>
16+
# include <exception>
17+
# include <memory>
18+
# include <thread>
19+
# include <type_traits>
20+
# include <typeinfo>
21+
# include <utility>
22+
# include <vector>
23+
#endif
2224

2325
#include "format.h"
2426
#include "ostream.h"
@@ -28,22 +30,24 @@
2830
#endif
2931
// Checking FMT_CPLUSPLUS for warning suppression in MSVC.
3032
#if FMT_CPLUSPLUS >= 201703L
31-
# if FMT_HAS_INCLUDE(<filesystem>)
33+
# if FMT_HAS_INCLUDE(<filesystem>) && !defined(FMT_IMPORT_STD)
3234
# include <filesystem>
3335
# endif
34-
# if FMT_HAS_INCLUDE(<variant>)
36+
# if FMT_HAS_INCLUDE(<variant>) && !defined(FMT_IMPORT_STD)
3537
# include <variant>
3638
# endif
37-
# if FMT_HAS_INCLUDE(<optional>)
39+
# if FMT_HAS_INCLUDE(<optional>) && !defined(FMT_IMPORT_STD)
3840
# include <optional>
3941
# endif
4042
#endif
4143

42-
#if FMT_HAS_INCLUDE(<expected>) && FMT_CPLUSPLUS > 202002L
44+
#if FMT_HAS_INCLUDE(<expected>) && FMT_CPLUSPLUS > 202002L && \
45+
!defined(FMT_IMPORT_STD)
4346
# include <expected>
4447
#endif
4548

46-
#if FMT_CPLUSPLUS > 201703L && FMT_HAS_INCLUDE(<source_location>)
49+
#if FMT_CPLUSPLUS > 201703L && FMT_HAS_INCLUDE(<source_location>) && \
50+
!defined(FMT_IMPORT_STD)
4751
# include <source_location>
4852
#endif
4953

include/fmt/xchar.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
#ifndef FMT_XCHAR_H_
99
#define FMT_XCHAR_H_
1010

11-
#include <cwchar>
11+
#ifndef FMT_IMPORT_STD
12+
# include <cwchar>
13+
#endif
1214

1315
#include "color.h"
1416
#include "format.h"
1517
#include "ranges.h"
1618

17-
#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
19+
#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) && !defined(FMT_IMPORT_STD)
1820
# include <locale>
1921
#endif
2022

src/fmt.cc

+37-30
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,44 @@ module;
22

33
// Put all implementation-provided headers into the global module fragment
44
// to prevent attachment to this module.
5-
#include <algorithm>
5+
#ifndef FMT_IMPORT_STD
6+
# include <algorithm>
7+
# include <chrono>
8+
# include <climits>
9+
# include <cmath>
10+
# include <cstddef>
11+
# include <cstdint>
12+
# include <cstdio>
13+
# include <cstdlib>
14+
# include <cstring>
15+
# include <ctime>
16+
# include <exception>
17+
# include <filesystem>
18+
# include <fstream>
19+
# include <functional>
20+
# include <iterator>
21+
# include <limits>
22+
# include <locale>
23+
# include <memory>
24+
# include <optional>
25+
# include <ostream>
26+
# include <stdexcept>
27+
# include <string>
28+
# include <string_view>
29+
# include <system_error>
30+
# include <thread>
31+
# include <type_traits>
32+
# include <typeinfo>
33+
# include <utility>
34+
# include <variant>
35+
# include <vector>
36+
#else
37+
# include <limits.h>
38+
# include <stdint.h>
39+
# include <stdio.h>
40+
# include <time.h>
41+
#endif
642
#include <cerrno>
7-
#include <chrono>
8-
#include <climits>
9-
#include <cmath>
10-
#include <cstddef>
11-
#include <cstdint>
12-
#include <cstdio>
13-
#include <cstdlib>
14-
#include <cstring>
15-
#include <ctime>
16-
#include <exception>
17-
#include <filesystem>
18-
#include <fstream>
19-
#include <functional>
20-
#include <iterator>
21-
#include <limits>
22-
#include <locale>
23-
#include <memory>
24-
#include <optional>
25-
#include <ostream>
26-
#include <stdexcept>
27-
#include <string>
28-
#include <string_view>
29-
#include <system_error>
30-
#include <thread>
31-
#include <type_traits>
32-
#include <typeinfo>
33-
#include <utility>
34-
#include <variant>
35-
#include <vector>
3643
#include <version>
3744

3845
#if __has_include(<cxxabi.h>)

src/os.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
#include "fmt/os.h"
1414

15-
#include <climits>
15+
#ifndef FMT_IMPORT_STD
16+
# include <climits>
17+
#endif
1618

1719
#if FMT_USE_FCNTL
1820
# include <sys/stat.h>

0 commit comments

Comments
 (0)