Skip to content

Commit 2cca51c

Browse files
committed
Issue 205: Make iostream support optional.
1 parent 221eeda commit 2cca51c

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

format.cc

+2
Original file line numberDiff line numberDiff line change
@@ -1252,11 +1252,13 @@ FMT_FUNC void fmt::print(CStringRef format_str, ArgList args) {
12521252
print(stdout, format_str, args);
12531253
}
12541254

1255+
#ifndef FMT_NO_STREAM_LIBRARIES
12551256
FMT_FUNC void fmt::print(std::ostream &os, CStringRef format_str, ArgList args) {
12561257
MemoryWriter w;
12571258
w.write(format_str, args);
12581259
os.write(w.data(), w.size());
12591260
}
1261+
#endif
12601262

12611263
FMT_FUNC void fmt::print_colored(Color c, CStringRef format, ArgList args) {
12621264
char escape[] = "\x1b[30m";

format.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@
3838
#include <limits>
3939
#include <stdexcept>
4040
#include <string>
41-
#include <sstream>
4241
#include <map>
4342

43+
#ifndef FMT_NO_STREAM_LIBRARIES
44+
# include <sstream>
45+
#endif
46+
4447
#if _SECURE_SCL
4548
# include <iterator>
4649
#endif
@@ -2685,6 +2688,8 @@ void print(std::FILE *f, CStringRef format_str, ArgList args);
26852688
*/
26862689
void print(CStringRef format_str, ArgList args);
26872690

2691+
2692+
#ifndef FMT_NO_STREAM_LIBRARIES
26882693
/**
26892694
\rst
26902695
Prints formatted data to the stream *os*.
@@ -2695,6 +2700,7 @@ void print(CStringRef format_str, ArgList args);
26952700
\endrst
26962701
*/
26972702
void print(std::ostream &os, CStringRef format_str, ArgList args);
2703+
#endif
26982704

26992705
template <typename Char>
27002706
void printf(BasicWriter<Char> &w, BasicCStringRef<Char> format, ArgList args) {
@@ -3007,7 +3013,11 @@ FMT_VARIADIC(std::string, format, CStringRef)
30073013
FMT_VARIADIC_W(std::wstring, format, WCStringRef)
30083014
FMT_VARIADIC(void, print, CStringRef)
30093015
FMT_VARIADIC(void, print, std::FILE *, CStringRef)
3016+
3017+
#ifndef FMT_NO_STREAM_LIBRARIES
30103018
FMT_VARIADIC(void, print, std::ostream &, CStringRef)
3019+
#endif
3020+
30113021
FMT_VARIADIC(void, print_colored, Color, CStringRef)
30123022
FMT_VARIADIC(std::string, sprintf, CStringRef)
30133023
FMT_VARIADIC_W(std::wstring, sprintf, WCStringRef)

test/format-test.cc

+2
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,7 @@ TEST(FormatIntTest, FormatDec) {
15391539
EXPECT_EQ("42", format_decimal(42ull));
15401540
}
15411541

1542+
#ifndef FMT_NO_STREAM_LIBRARIES
15421543
TEST(FormatTest, Print) {
15431544
#if FMT_USE_FILE_DESCRIPTORS
15441545
EXPECT_WRITE(stdout, fmt::print("Don't {}!", "panic"), "Don't panic!");
@@ -1549,6 +1550,7 @@ TEST(FormatTest, Print) {
15491550
fmt::print(os, "Don't {}!", "panic");
15501551
EXPECT_EQ("Don't panic!", os.str());
15511552
}
1553+
#endif
15521554

15531555
#if FMT_USE_FILE_DESCRIPTORS
15541556
TEST(FormatTest, PrintColored) {

0 commit comments

Comments
 (0)