Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
a95c6a5a
Commit
a95c6a5a
authored
Dec 02, 2009
by
zhanyong.wan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes a C++-standard-compliance bug in gmock-printers.h.
parent
f6d6a22b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
54 deletions
+59
-54
gmock-printers.h
include/gmock/gmock-printers.h
+59
-54
No files found.
include/gmock/gmock-printers.h
View file @
a95c6a5a
...
@@ -434,63 +434,10 @@ inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {
...
@@ -434,63 +434,10 @@ inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {
// Overload for ::std::tr1::tuple. Needed for printing function
// Overload for ::std::tr1::tuple. Needed for printing function
// arguments, which are packed as tuples.
// arguments, which are packed as tuples.
typedef
::
std
::
vector
<
string
>
Strings
;
// This helper template allows PrintTo() for tuples and
// UniversalTersePrintTupleFieldsToStrings() to be defined by
// induction on the number of tuple fields. The idea is that
// TuplePrefixPrinter<N>::PrintPrefixTo(t, os) prints the first N
// fields in tuple t, and can be defined in terms of
// TuplePrefixPrinter<N - 1>.
// The inductive case.
template
<
size_t
N
>
struct
TuplePrefixPrinter
{
// Prints the first N fields of a tuple.
template
<
typename
Tuple
>
static
void
PrintPrefixTo
(
const
Tuple
&
t
,
::
std
::
ostream
*
os
)
{
TuplePrefixPrinter
<
N
-
1
>::
PrintPrefixTo
(
t
,
os
);
*
os
<<
", "
;
UniversalPrinter
<
typename
::
std
::
tr1
::
tuple_element
<
N
-
1
,
Tuple
>::
type
>
::
Print
(
::
std
::
tr1
::
get
<
N
-
1
>
(
t
),
os
);
}
// Tersely prints the first N fields of a tuple to a string vector,
// one element for each field.
template
<
typename
Tuple
>
static
void
TersePrintPrefixToStrings
(
const
Tuple
&
t
,
Strings
*
strings
)
{
TuplePrefixPrinter
<
N
-
1
>::
TersePrintPrefixToStrings
(
t
,
strings
);
::
std
::
stringstream
ss
;
UniversalTersePrint
(
::
std
::
tr1
::
get
<
N
-
1
>
(
t
),
&
ss
);
strings
->
push_back
(
ss
.
str
());
}
};
// Base cases.
template
<>
struct
TuplePrefixPrinter
<
0
>
{
template
<
typename
Tuple
>
static
void
PrintPrefixTo
(
const
Tuple
&
,
::
std
::
ostream
*
)
{}
template
<
typename
Tuple
>
static
void
TersePrintPrefixToStrings
(
const
Tuple
&
,
Strings
*
)
{}
};
template
<>
template
<
typename
Tuple
>
void
TuplePrefixPrinter
<
1
>::
PrintPrefixTo
(
const
Tuple
&
t
,
::
std
::
ostream
*
os
)
{
UniversalPrinter
<
typename
::
std
::
tr1
::
tuple_element
<
0
,
Tuple
>::
type
>::
Print
(
::
std
::
tr1
::
get
<
0
>
(
t
),
os
);
}
// Helper function for printing a tuple. T must be instantiated with
// Helper function for printing a tuple. T must be instantiated with
// a tuple type.
// a tuple type.
template
<
typename
T
>
template
<
typename
T
>
void
PrintTupleTo
(
const
T
&
t
,
::
std
::
ostream
*
os
)
{
void
PrintTupleTo
(
const
T
&
t
,
::
std
::
ostream
*
os
);
*
os
<<
"("
;
TuplePrefixPrinter
<
::
std
::
tr1
::
tuple_size
<
T
>::
value
>::
PrintPrefixTo
(
t
,
os
);
*
os
<<
")"
;
}
// Overloaded PrintTo() for tuples of various arities. We support
// Overloaded PrintTo() for tuples of various arities. We support
// tuples of up-to 10 fields. The following implementation works
// tuples of up-to 10 fields. The following implementation works
...
@@ -725,6 +672,64 @@ void UniversalPrint(const T& value, ::std::ostream* os) {
...
@@ -725,6 +672,64 @@ void UniversalPrint(const T& value, ::std::ostream* os) {
UniversalPrinter
<
T
>::
Print
(
value
,
os
);
UniversalPrinter
<
T
>::
Print
(
value
,
os
);
}
}
typedef
::
std
::
vector
<
string
>
Strings
;
// This helper template allows PrintTo() for tuples and
// UniversalTersePrintTupleFieldsToStrings() to be defined by
// induction on the number of tuple fields. The idea is that
// TuplePrefixPrinter<N>::PrintPrefixTo(t, os) prints the first N
// fields in tuple t, and can be defined in terms of
// TuplePrefixPrinter<N - 1>.
// The inductive case.
template
<
size_t
N
>
struct
TuplePrefixPrinter
{
// Prints the first N fields of a tuple.
template
<
typename
Tuple
>
static
void
PrintPrefixTo
(
const
Tuple
&
t
,
::
std
::
ostream
*
os
)
{
TuplePrefixPrinter
<
N
-
1
>::
PrintPrefixTo
(
t
,
os
);
*
os
<<
", "
;
UniversalPrinter
<
typename
::
std
::
tr1
::
tuple_element
<
N
-
1
,
Tuple
>::
type
>
::
Print
(
::
std
::
tr1
::
get
<
N
-
1
>
(
t
),
os
);
}
// Tersely prints the first N fields of a tuple to a string vector,
// one element for each field.
template
<
typename
Tuple
>
static
void
TersePrintPrefixToStrings
(
const
Tuple
&
t
,
Strings
*
strings
)
{
TuplePrefixPrinter
<
N
-
1
>::
TersePrintPrefixToStrings
(
t
,
strings
);
::
std
::
stringstream
ss
;
UniversalTersePrint
(
::
std
::
tr1
::
get
<
N
-
1
>
(
t
),
&
ss
);
strings
->
push_back
(
ss
.
str
());
}
};
// Base cases.
template
<>
struct
TuplePrefixPrinter
<
0
>
{
template
<
typename
Tuple
>
static
void
PrintPrefixTo
(
const
Tuple
&
,
::
std
::
ostream
*
)
{}
template
<
typename
Tuple
>
static
void
TersePrintPrefixToStrings
(
const
Tuple
&
,
Strings
*
)
{}
};
template
<>
template
<
typename
Tuple
>
void
TuplePrefixPrinter
<
1
>::
PrintPrefixTo
(
const
Tuple
&
t
,
::
std
::
ostream
*
os
)
{
UniversalPrinter
<
typename
::
std
::
tr1
::
tuple_element
<
0
,
Tuple
>::
type
>::
Print
(
::
std
::
tr1
::
get
<
0
>
(
t
),
os
);
}
// Helper function for printing a tuple. T must be instantiated with
// a tuple type.
template
<
typename
T
>
void
PrintTupleTo
(
const
T
&
t
,
::
std
::
ostream
*
os
)
{
*
os
<<
"("
;
TuplePrefixPrinter
<
::
std
::
tr1
::
tuple_size
<
T
>::
value
>::
PrintPrefixTo
(
t
,
os
);
*
os
<<
")"
;
}
// Prints the fields of a tuple tersely to a string vector, one
// Prints the fields of a tuple tersely to a string vector, one
// element for each field. See the comment before
// element for each field. See the comment before
// UniversalTersePrint() for how we define "tersely".
// UniversalTersePrint() for how we define "tersely".
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment