From bc7be8320e3fde1cc11fd7972646cfde6904a18b Mon Sep 17 00:00:00 2001 From: Yi Wang Date: Fri, 9 Feb 2018 19:33:44 -0800 Subject: [PATCH] Update pre-commit --- paddle/fluid/pybind/pybind.h | 14 ++++ paddle/string/piece.h | 4 +- paddle/string/printf_test.cc | 4 +- paddle/string/tinyformat/tinyformat.h | 106 ++++++++++++++++---------- paddle/string/to_string_test.cc | 2 +- 5 files changed, 84 insertions(+), 46 deletions(-) diff --git a/paddle/fluid/pybind/pybind.h b/paddle/fluid/pybind/pybind.h index b3ea649a5b..eac0b35e49 100644 --- a/paddle/fluid/pybind/pybind.h +++ b/paddle/fluid/pybind/pybind.h @@ -1,3 +1,17 @@ +// Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + // Generated by the paddle/operator/CMakeLists.txt. DO NOT EDIT! USE_CUDA_ONLY_OP(ncclAllReduce); diff --git a/paddle/string/piece.h b/paddle/string/piece.h index f2bb6b2c76..dcef9791a7 100644 --- a/paddle/string/piece.h +++ b/paddle/string/piece.h @@ -28,7 +28,7 @@ namespace string { // its syntax is simple as it doesn't own/manage the string, it is // cheap to construct Pieces and pass them around. class Piece { - public: +public: static const size_t npos = static_cast(-1); // We provide non-explicit singleton constructors so users can @@ -55,7 +55,7 @@ class Piece { // Return a string that contains the copy of the referenced data. std::string ToString() const { return std::string(data_, size_); } - private: +private: const char* data_; size_t size_; diff --git a/paddle/string/printf_test.cc b/paddle/string/printf_test.cc index b5ad35513b..9815f29bdd 100644 --- a/paddle/string/printf_test.cc +++ b/paddle/string/printf_test.cc @@ -24,6 +24,6 @@ TEST(StringPrintf, StringPrintf) { long hour = 14; int min = 44; EXPECT_EQ(std::string("Wednesday, July 27, 14:44"), - paddle::string::Sprintf("%s, %s %d, %.2d:%.2d", weekday, month, day, - hour, min)); + paddle::string::Sprintf( + "%s, %s %d, %.2d:%.2d", weekday, month, day, hour, min)); } diff --git a/paddle/string/tinyformat/tinyformat.h b/paddle/string/tinyformat/tinyformat.h index d1a2c47f1a..270198dc52 100644 --- a/paddle/string/tinyformat/tinyformat.h +++ b/paddle/string/tinyformat/tinyformat.h @@ -147,7 +147,7 @@ namespace detail { // Test whether type T1 is convertible to type T2 template struct is_convertible { - private: +private: // two types of different size struct fail { char dummy[2]; @@ -160,7 +160,7 @@ struct is_convertible { static succeed tryConvert(const T2 &); static const T1 &makeT1(); - public: +public: // Standard trick: the (...) version of tryConvert will be chosen from // the overload set only if the version taking a T2 doesn't match. // Then we compare the sizes of the return types to check which @@ -170,7 +170,8 @@ struct is_convertible { // Format the value by casting to type fmtT. This default implementation // should never be called. -template ::value> struct formatValueAsType { static void invoke(std::ostream & /*out*/, const T & /*value*/) { assert(0); } @@ -240,8 +241,11 @@ TINYFORMAT_DEFINE_FORMAT_TRUNCATED_CSTR(char) /// operator<< to format the type T, with special cases for the %c and %p /// conversions. template -inline void formatValue(std::ostream &out, const char * /*fmtBegin*/, - const char *fmtEnd, int ntrunc, const T &value) { +inline void formatValue(std::ostream &out, + const char * /*fmtBegin*/, + const char *fmtEnd, + int ntrunc, + const T &value) { // The mess here is to support the %c and %p conversions: if these // conversions are active we try to convert the type to a char or const // void* respectively and format that instead of the value itself. For the @@ -263,22 +267,25 @@ inline void formatValue(std::ostream &out, const char * /*fmtBegin*/, } // Overloaded version for char types to support printing as an integer -#define TINYFORMAT_DEFINE_FORMATVALUE_CHAR(charType) \ - inline void formatValue(std::ostream &out, const char * /*fmtBegin*/, \ - const char *fmtEnd, int /**/, charType value) { \ - switch (*(fmtEnd - 1)) { \ - case 'u': \ - case 'd': \ - case 'i': \ - case 'o': \ - case 'X': \ - case 'x': \ - out << static_cast(value); \ - break; \ - default: \ - out << value; \ - break; \ - } \ +#define TINYFORMAT_DEFINE_FORMATVALUE_CHAR(charType) \ + inline void formatValue(std::ostream &out, \ + const char * /*fmtBegin*/, \ + const char *fmtEnd, \ + int /**/, \ + charType value) { \ + switch (*(fmtEnd - 1)) { \ + case 'u': \ + case 'd': \ + case 'i': \ + case 'o': \ + case 'X': \ + case 'x': \ + out << static_cast(value); \ + break; \ + default: \ + out << value; \ + break; \ + } \ } // per 3.9.1: char, signed char and unsigned char are all distinct types TINYFORMAT_DEFINE_FORMATVALUE_CHAR(char) @@ -475,7 +482,7 @@ namespace detail { // each argument to be allocated as a homogenous array inside FormatList // whereas a naive implementation based on inheritance does not. class FormatArg { - public: +public: FormatArg() {} template @@ -484,17 +491,22 @@ class FormatArg { m_formatImpl(&formatImpl), m_toIntImpl(&toIntImpl) {} - void format(std::ostream &out, const char *fmtBegin, const char *fmtEnd, + void format(std::ostream &out, + const char *fmtBegin, + const char *fmtEnd, int ntrunc) const { m_formatImpl(out, fmtBegin, fmtEnd, ntrunc, m_value); } int toInt() const { return m_toIntImpl(m_value); } - private: +private: template - static void formatImpl(std::ostream &out, const char *fmtBegin, - const char *fmtEnd, int ntrunc, const void *value) { + static void formatImpl(std::ostream &out, + const char *fmtBegin, + const char *fmtEnd, + int ntrunc, + const void *value) { formatValue(out, fmtBegin, fmtEnd, ntrunc, *static_cast(value)); } @@ -504,8 +516,11 @@ class FormatArg { } const void *m_value; - void (*m_formatImpl)(std::ostream &out, const char *fmtBegin, - const char *fmtEnd, int ntrunc, const void *value); + void (*m_formatImpl)(std::ostream &out, + const char *fmtBegin, + const char *fmtEnd, + int ntrunc, + const void *value); int (*m_toIntImpl)(const void *value); }; @@ -554,10 +569,12 @@ inline const char *printFormatStringLiteral(std::ostream &out, // necessary to pull out variable width and precision . The function returns a // pointer to the character after the end of the current format spec. inline const char *streamStateFromFormat(std::ostream &out, - bool &spacePadPositive, int &ntrunc, + bool &spacePadPositive, + int &ntrunc, const char *fmtStart, const detail::FormatArg *formatters, - int &argIndex, int numFormatters) { + int &argIndex, + int numFormatters) { if (*fmtStart != '%') { TINYFORMAT_ERROR( "tinyformat: Not enough conversion specifiers in format string"); @@ -733,8 +750,10 @@ inline const char *streamStateFromFormat(std::ostream &out, } //------------------------------------------------------------------------------ -inline void formatImpl(std::ostream &out, const char *fmt, - const detail::FormatArg *formatters, int numFormatters) { +inline void formatImpl(std::ostream &out, + const char *fmt, + const detail::FormatArg *formatters, + int numFormatters) { // Saved stream state std::streamsize origWidth = out.width(); std::streamsize origPrecision = out.precision(); @@ -746,9 +765,13 @@ inline void formatImpl(std::ostream &out, const char *fmt, fmt = printFormatStringLiteral(out, fmt); bool spacePadPositive = false; int ntrunc = -1; - const char *fmtEnd = - streamStateFromFormat(out, spacePadPositive, ntrunc, fmt, formatters, - argIndex, numFormatters); + const char *fmtEnd = streamStateFromFormat(out, + spacePadPositive, + ntrunc, + fmt, + formatters, + argIndex, + numFormatters); if (argIndex >= numFormatters) { // Check args remain after reading any variable width/precision TINYFORMAT_ERROR("tinyformat: Not enough format arguments"); @@ -797,14 +820,15 @@ inline void formatImpl(std::ostream &out, const char *fmt, /// information has been stripped from the arguments, leaving just enough of a /// common interface to perform formatting as required. class FormatList { - public: +public: FormatList(detail::FormatArg *formatters, int N) : m_formatters(formatters), m_N(N) {} - friend void vformat(std::ostream &out, const char *fmt, + friend void vformat(std::ostream &out, + const char *fmt, const FormatList &list); - private: +private: const detail::FormatArg *m_formatters; int m_N; }; @@ -817,7 +841,7 @@ namespace detail { // Format list subclass with fixed storage to avoid dynamic allocation template class FormatListN : public FormatList { - public: +public: template FormatListN(const Args &... args) : FormatList(&m_formatterStore[0], N), @@ -825,14 +849,14 @@ class FormatListN : public FormatList { static_assert(sizeof...(args) == N, "Number of args must be N"); } - private: +private: FormatArg m_formatterStore[N]; }; // Special 0-arg version - MSVC says zero-sized C array in struct is nonstandard template <> class FormatListN<0> : public FormatList { - public: +public: FormatListN() : FormatList(0, 0) {} }; diff --git a/paddle/string/to_string_test.cc b/paddle/string/to_string_test.cc index 4956bd96fa..05650ee8f1 100644 --- a/paddle/string/to_string_test.cc +++ b/paddle/string/to_string_test.cc @@ -17,7 +17,7 @@ limitations under the License. */ constexpr char kOutputString[] = "User Defined Output"; class UserDefinedClass { - public: +public: }; std::ostream& operator<<(std::ostream& s, const UserDefinedClass& ins) { -- GitLab