Skip to content

Commit ab5b315

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

13 files changed

+137
-98
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

+6-4
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 <cmath>
14+
# include <exception>
15+
#endif
1216
#include <cerrno> // errno
1317
#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

+17-12
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,35 @@
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 && \
60+
!defined(FMT_IMPORT_STD)
5861
# include <bit> // std::bit_cast
5962
#endif
6063

6164
// libc++ supports string_view in pre-c++17.
6265
#if FMT_HAS_INCLUDE(<string_view>) && \
6366
(FMT_CPLUSPLUS >= 201703L || defined(_LIBCPP_VERSION))
64-
# include <string_view>
67+
# ifndef FMT_IMPORT_STD
68+
# include <string_view>
69+
# endif
6570
# define FMT_USE_STRING_VIEW
6671
#endif
6772

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

+31-26
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,48 @@
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"
2527

2628
#if FMT_HAS_INCLUDE(<version>)
2729
# include <version>
2830
#endif
31+
32+
#ifndef FMT_IMPORT_STD
2933
// Checking FMT_CPLUSPLUS for warning suppression in MSVC.
30-
#if FMT_CPLUSPLUS >= 201703L
31-
# if FMT_HAS_INCLUDE(<filesystem>)
32-
# include <filesystem>
33-
# endif
34-
# if FMT_HAS_INCLUDE(<variant>)
35-
# include <variant>
36-
# endif
37-
# if FMT_HAS_INCLUDE(<optional>)
38-
# include <optional>
34+
# if FMT_CPLUSPLUS >= 201703L
35+
# if FMT_HAS_INCLUDE(<filesystem>)
36+
# include <filesystem>
37+
# endif
38+
# if FMT_HAS_INCLUDE(<variant>)
39+
# include <variant>
40+
# endif
41+
# if FMT_HAS_INCLUDE(<optional>)
42+
# include <optional>
43+
# endif
3944
# endif
40-
#endif
4145

42-
#if FMT_HAS_INCLUDE(<expected>) && FMT_CPLUSPLUS > 202002L
43-
# include <expected>
44-
#endif
46+
# if FMT_HAS_INCLUDE(<expected>) && FMT_CPLUSPLUS > 202002L
47+
# include <expected>
48+
# endif
4549

46-
#if FMT_CPLUSPLUS > 201703L && FMT_HAS_INCLUDE(<source_location>)
47-
# include <source_location>
50+
# if FMT_CPLUSPLUS > 201703L && FMT_HAS_INCLUDE(<source_location>)
51+
# include <source_location>
52+
# endif
4853
#endif
4954

5055
// GCC 4 does not support FMT_HAS_INCLUDE.

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

+36-29
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 <cmath>
9+
# include <cstddef>
10+
# include <cstdint>
11+
# include <cstdio>
12+
# include <cstdlib>
13+
# include <cstring>
14+
# include <ctime>
15+
# include <exception>
16+
# include <filesystem>
17+
# include <fstream>
18+
# include <functional>
19+
# include <iterator>
20+
# include <limits>
21+
# include <locale>
22+
# include <memory>
23+
# include <optional>
24+
# include <ostream>
25+
# include <stdexcept>
26+
# include <string>
27+
# include <string_view>
28+
# include <system_error>
29+
# include <thread>
30+
# include <type_traits>
31+
# include <typeinfo>
32+
# include <utility>
33+
# include <variant>
34+
# include <vector>
35+
#else
36+
# include <limits.h>
37+
# include <stdint.h>
38+
# include <stdio.h>
39+
# include <time.h>
40+
#endif
641
#include <cerrno>
7-
#include <chrono>
842
#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>)

0 commit comments

Comments
 (0)