From 5a7d0d75ee3a7bcb442ef42c0ddbe53e4c7b2198 Mon Sep 17 00:00:00 2001 From: Marc Horowitz Date: Wed, 15 Jan 2014 18:44:14 -0800 Subject: [PATCH] move folly::detail::IsSomeString outside of folly::detail Summary: It is useful when writing additional specializations of of toAppend() and related functions to use IsSomeString, the same way the ones in Conv.h do. Move IsSomeString out of detail, so outside code doesn't access a detail namespace inappropriately. Test Plan: fbmake runtests; arc lint Reviewed By: tudorb@fb.com FB internal diff: D1130910 --- folly/Conv.h | 51 ++++++++++++++++++++++++---------------------- folly/Format-inl.h | 4 ++-- folly/Format.h | 8 ++++---- 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/folly/Conv.h b/folly/Conv.h index 75c243c4..12936cc3 100644 --- a/folly/Conv.h +++ b/folly/Conv.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 Facebook, Inc. + * Copyright 2014 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -104,11 +104,6 @@ to(const Src & value) { namespace detail { -template struct IsSomeString { - enum { value = std::is_same::value - || std::is_same::value }; -}; - template const T& getLastElement(const T & v) { return v; @@ -245,13 +240,21 @@ void toAppend(char value, Tgt * result) { *result += value; } +/** + * Ubiquitous helper template for writing string appenders + */ +template struct IsSomeString { + enum { value = std::is_same::value + || std::is_same::value }; +}; + /** * Everything implicitly convertible to const char* gets appended. */ template typename std::enable_if< std::is_convertible::value - && detail::IsSomeString::value>::type + && IsSomeString::value>::type toAppend(Src value, Tgt * result) { // Treat null pointers like an empty string, as in: // operator<<(std::ostream&, const char*). @@ -266,7 +269,7 @@ toAppend(Src value, Tgt * result) { */ template typename std::enable_if< - detail::IsSomeString::value && detail::IsSomeString::value>::type + IsSomeString::value && IsSomeString::value>::type toAppend(const Src& value, Tgt * result) { result->append(value); } @@ -276,7 +279,7 @@ toAppend(const Src& value, Tgt * result) { */ template typename std::enable_if< - detail::IsSomeString::value>::type + IsSomeString::value>::type toAppend(StringPiece value, Tgt * result) { result->append(value.data(), value.size()); } @@ -287,7 +290,7 @@ toAppend(StringPiece value, Tgt * result) { */ template typename std::enable_if< - detail::IsSomeString::value>::type + IsSomeString::value>::type toAppend(const fbstring& value, Tgt * result) { result->append(value.data(), value.size()); } @@ -338,7 +341,7 @@ toAppend(unsigned __int128 value, Tgt * result) { template typename std::enable_if< std::is_integral::value && std::is_signed::value && - detail::IsSomeString::value && sizeof(Src) >= 4>::type + IsSomeString::value && sizeof(Src) >= 4>::type toAppend(Src value, Tgt * result) { char buffer[20]; if (value < 0) { @@ -355,7 +358,7 @@ toAppend(Src value, Tgt * result) { template typename std::enable_if< std::is_integral::value && !std::is_signed::value - && detail::IsSomeString::value && sizeof(Src) >= 4>::type + && IsSomeString::value && sizeof(Src) >= 4>::type toAppend(Src value, Tgt * result) { char buffer[20]; result->append(buffer, buffer + uint64ToBufferUnsafe(value, buffer)); @@ -368,7 +371,7 @@ toAppend(Src value, Tgt * result) { template typename std::enable_if< std::is_integral::value - && detail::IsSomeString::value && sizeof(Src) < 4>::type + && IsSomeString::value && sizeof(Src) < 4>::type toAppend(Src value, Tgt * result) { typedef typename std::conditional::value, int64_t, uint64_t>::type @@ -384,7 +387,7 @@ toAppend(Src value, Tgt * result) { */ template typename std::enable_if< - std::is_enum::value && detail::IsSomeString::value>::type + std::is_enum::value && IsSomeString::value>::type toAppend(Src value, Tgt * result) { toAppend( static_cast::type>(value), result); @@ -397,7 +400,7 @@ toAppend(Src value, Tgt * result) { */ template typename std::enable_if< - std::is_enum::value && detail::IsSomeString::value>::type + std::is_enum::value && IsSomeString::value>::type toAppend(Src value, Tgt * result) { /* static */ if (Src(-1) < 0) { /* static */ if (sizeof(Src) <= sizeof(int)) { @@ -424,7 +427,7 @@ toAppend(Src value, Tgt * result) { template typename std::enable_if< std::is_floating_point::value - && detail::IsSomeString::value>::type + && IsSomeString::value>::type toAppend( Src value, Tgt * result, @@ -463,7 +466,7 @@ toAppend( template typename std::enable_if< std::is_floating_point::value - && detail::IsSomeString::value>::type + && IsSomeString::value>::type toAppend(Src value, Tgt * result) { toAppend( value, result, double_conversion::DoubleToStringConverter::SHORTEST, 0); @@ -474,7 +477,7 @@ toAppend(Src value, Tgt * result) { */ template typename std::enable_if= 2 - && detail::IsSomeString< + && IsSomeString< typename std::remove_pointer< typename detail::last_element::type >::type>::value>::type @@ -487,7 +490,7 @@ toAppend(const T& v, const Ts&... vs) { * Variadic base case: do nothing. */ template -typename std::enable_if::value>::type +typename std::enable_if::value>::type toAppend(Tgt* result) { } @@ -495,7 +498,7 @@ toAppend(Tgt* result) { * Variadic base case: do nothing. */ template -typename std::enable_if::value>::type +typename std::enable_if::value>::type toAppendDelim(const Delimiter& delim, Tgt* result) { } @@ -503,7 +506,7 @@ toAppendDelim(const Delimiter& delim, Tgt* result) { * 1 element: same as toAppend. */ template -typename std::enable_if::value>::type +typename std::enable_if::value>::type toAppendDelim(const Delimiter& delim, const T& v, Tgt* tgt) { toAppend(v, tgt); } @@ -513,7 +516,7 @@ toAppendDelim(const Delimiter& delim, const T& v, Tgt* tgt) { */ template typename std::enable_if= 2 - && detail::IsSomeString< + && IsSomeString< typename std::remove_pointer< typename detail::last_element::type >::type>::value>::type @@ -527,7 +530,7 @@ toAppendDelim(const Delimiter& delim, const T& v, const Ts&... vs) { * for all types. */ template -typename std::enable_if::value, Tgt>::type +typename std::enable_if::value, Tgt>::type to(const Ts&... vs) { Tgt result; toAppend(vs..., &result); @@ -539,7 +542,7 @@ to(const Ts&... vs) { * back-end for all types. */ template -typename std::enable_if::value, Tgt>::type +typename std::enable_if::value, Tgt>::type toDelim(const Delim& delim, const Ts&... vs) { Tgt result; toAppendDelim(delim, vs..., &result); diff --git a/folly/Format-inl.h b/folly/Format-inl.h index b8eb0a16..8f4bb8e9 100644 --- a/folly/Format-inl.h +++ b/folly/Format-inl.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 Facebook, Inc. + * Copyright 2014 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1112,7 +1112,7 @@ class FormatValue, void> { */ template typename std::enable_if< - detail::IsSomeString::value>::type + IsSomeString::value>::type toAppend(const Formatter& value, Tgt * result) { value.appendTo(*result); } diff --git a/folly/Format.h b/folly/Format.h index dae9ae4b..589bcdff 100644 --- a/folly/Format.h +++ b/folly/Format.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 Facebook, Inc. + * Copyright 2014 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -76,7 +76,7 @@ class Formatter { * Append to a string. */ template - typename std::enable_if::value>::type + typename std::enable_if::value>::type appendTo(Str& str) const { auto appender = [&str] (StringPiece s) { str.append(s.data(), s.size()); }; (*this)(appender); @@ -202,7 +202,7 @@ Formatter vformat(StringPiece fmt, Container&& container) { * Shortcut for toAppend(format(...), &foo); */ template -typename std::enable_if::value>::type +typename std::enable_if::value>::type format(Str* out, StringPiece fmt, Args&&... args) { format(fmt, std::forward(args)...).appendTo(*out); } @@ -211,7 +211,7 @@ format(Str* out, StringPiece fmt, Args&&... args) { * Append vformatted output to a string. */ template -typename std::enable_if::value>::type +typename std::enable_if::value>::type vformat(Str* out, StringPiece fmt, Container&& container) { vformat(fmt, std::forward(container)).appendTo(*out); } -- 2.34.1