Skip to content

Commit

Permalink
less insane includes
Browse files Browse the repository at this point in the history
  • Loading branch information
panzi committed May 22, 2014
1 parent a0e5740 commit a70c3e7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
4 changes: 1 addition & 3 deletions include/formatstring/format_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "formatstring/config.h"
#include "formatstring/formatter.h"
#include "formatstring/format_traits_fwd.h"

#include <type_traits>

Expand All @@ -13,9 +14,6 @@ namespace formatstring {
using if_derived = typename std::enable_if<std::is_base_of<Base, Derived>::value>::type;

// ---- fallback ----
template<typename Char, typename T, typename ENABLE = void>
struct format_traits;

template<typename Char, typename T, typename ENABLE>
struct format_traits {
typedef Char char_type;
Expand Down
12 changes: 12 additions & 0 deletions include/formatstring/format_traits_fwd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef FORMATSTRING_FORMAT_TRAITS_FWD_H
#define FORMATSTRING_FORMAT_TRAITS_FWD_H
#pragma once

namespace formatstring {

template<typename Char, typename T, typename ENABLE = void>
struct format_traits;

}

#endif // FORMATSTRING_FORMAT_TRAITS_FWD_H
1 change: 1 addition & 0 deletions include/formatstring/formattedvalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "formatstring/formatter.h"
#include "formatstring/formatspec.h"
#include "formatstring/formatvalue.h"
#include "formatstring/format_traits.h"

#include <sstream>

Expand Down
27 changes: 12 additions & 15 deletions include/formatstring/formatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "formatstring/formatvalue.h"
#include "formatstring/conversion.h"
#include "formatstring/formatspec.h"
#include "formatstring/format_traits_fwd.h"

namespace formatstring {

Expand Down Expand Up @@ -49,6 +50,17 @@ namespace formatstring {
template<typename Char, typename Last>
inline void unpack_formatters(BasicFormatters<Char>& formatters, const Last& last);

template<typename Char, typename First, typename... Rest>
inline void unpack_formatters(BasicFormatters<Char>& formatters, const First& first, const Rest&... rest) {
formatters.emplace_back(format_traits<Char,First>::make_formatter(first));
unpack_formatters<Char, Rest...>(formatters, rest...);
}

template<typename Char, typename Last>
inline void unpack_formatters(BasicFormatters<Char>& formatters, const Last& last) {
formatters.emplace_back(format_traits<Char,Last>::make_formatter(last));
}

template<typename Char, typename T,
void _format(std::basic_ostream<Char>& out, T value, const BasicFormatSpec<Char>& spec) = format_value,
void _repr(std::basic_ostream<Char>& out, T value) = repr_value>
Expand Down Expand Up @@ -136,19 +148,4 @@ namespace formatstring {
}
}

// include is here because of circular dependency
#include "formatstring/format_traits.h"

// ==== unpack_formatters ====
template<typename Char, typename First, typename... Rest>
inline void formatstring::unpack_formatters(BasicFormatters<Char>& formatters, const First& first, const Rest&... rest) {
formatters.emplace_back(format_traits<Char,First>::make_formatter(first));
unpack_formatters<Char, Rest...>(formatters, rest...);
}

template<typename Char, typename Last>
inline void formatstring::unpack_formatters(BasicFormatters<Char>& formatters, const Last& last) {
formatters.emplace_back(format_traits<Char,Last>::make_formatter(last));
}

#endif // FORMATSTRING_FORMATTER_H
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ add_library(${FORMATSTRING_NAME} SHARED
../include/formatstring/formatitem.h
../include/formatstring/formatspec.h
../include/formatstring/formatter.h
../include/formatstring/format_traits_fwd.h
../include/formatstring/format_traits.h
../include/formatstring/formattedvalue.h
../include/formatstring/formatvalue.h
Expand Down

0 comments on commit a70c3e7

Please sign in to comment.