X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;ds=sidebyside;f=folly%2FFormat.h;h=c34f333978d3bd4f7a06f6c8483f14d881c5e3c5;hb=0826d16bb14b477fa619a4a30f4d8c000f381ff4;hp=7ffc1527ba3d1528377351e2a8aaa6fbec3027e5;hpb=4ecf6e3f6d120907c0e32059a923d15cd6fcfedc;p=folly.git diff --git a/folly/Format.h b/folly/Format.h index 7ffc1527..c34f3339 100644 --- a/folly/Format.h +++ b/folly/Format.h @@ -1,5 +1,5 @@ /* - * Copyright 2015 Facebook, Inc. + * Copyright 2016 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,27 +14,17 @@ * limitations under the License. */ -#ifndef FOLLY_FORMAT_H_ +#pragma once #define FOLLY_FORMAT_H_ -#include #include #include #include -#include -#include -#include -#include -#include - -#include #include #include #include -#include #include -#include #include // Ignore shadowing warnings within this file, so includers can use -Wshadow. @@ -118,7 +108,7 @@ class BaseFormatter { template typename std::enable_if::type - doFormatFrom(size_t i, FormatArg& arg, Callback& cb) const { + doFormatFrom(size_t i, FormatArg& arg, Callback& /*cb*/) const { arg.error("argument index out of range, max=", i); } @@ -137,6 +127,39 @@ class BaseFormatter { return doFormatFrom<0>(i, arg, cb); } + template + typename std::enable_if::type + getSizeArgFrom(size_t i, const FormatArg& arg) const { + arg.error("argument index out of range, max=", i); + } + + template + typename std::enable_if::value && + !std::is_same::value, int>::type + getValue(const FormatValue& format, const FormatArg&) const { + return static_cast(format.getValue()); + } + + template + typename std::enable_if::value || + std::is_same::value, int>::type + getValue(const FormatValue&, const FormatArg& arg) const { + arg.error("dynamic field width argument must be integral"); + } + + template + typename std::enable_if::type + getSizeArgFrom(size_t i, const FormatArg& arg) const { + if (i == K) { + return getValue(std::get(values_), arg); + } + return getSizeArgFrom(i, arg); + } + + int getSizeArg(size_t i, const FormatArg& arg) const { + return getSizeArgFrom<0>(i, arg); + } + StringPiece str_; protected: @@ -410,5 +433,3 @@ vformatChecked(Str* out, StringPiece fmt, Container&& container) { #include #pragma GCC diagnostic pop - -#endif /* FOLLY_FORMAT_H_ */