Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
6d06398a
Commit
6d06398a
authored
Nov 21, 2020
by
lrita
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make butil::ScopedVector<T> support initializer_list
parent
31eba304
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
0 deletions
+17
-0
scoped_vector.h
src/butil/memory/scoped_vector.h
+6
-0
scoped_vector_unittest.cc
test/scoped_vector_unittest.cc
+11
-0
No files found.
src/butil/memory/scoped_vector.h
View file @
6d06398a
...
...
@@ -6,6 +6,9 @@
#define BUTIL_MEMORY_SCOPED_VECTOR_H_
#include <vector>
#if __cplusplus >= 201103L // >= C++11
#include <initializer_list>
#endif
#include "butil/basictypes.h"
#include "butil/logging.h"
...
...
@@ -38,6 +41,9 @@ class ScopedVector {
ScopedVector
()
{}
~
ScopedVector
()
{
clear
();
}
ScopedVector
(
RValue
other
)
{
swap
(
*
other
.
object
);
}
#if __cplusplus >= 201103L // < C++11
ScopedVector
(
std
::
initializer_list
<
value_type
>
il
)
:
v_
(
il
)
{}
#endif // __cplusplus < 201103L
ScopedVector
&
operator
=
(
RValue
rhs
)
{
swap
(
*
rhs
.
object
);
...
...
test/scoped_vector_unittest.cc
View file @
6d06398a
...
...
@@ -203,6 +203,17 @@ TEST(ScopedVectorTest, Scope) {
EXPECT_EQ
(
LC_DESTROYED
,
watcher
.
life_cycle_state
());
}
TEST
(
ScopedVectorTest
,
Scope2
)
{
LifeCycleWatcher
watcher
;
EXPECT_EQ
(
LC_INITIAL
,
watcher
.
life_cycle_state
());
{
butil
::
ScopedVector
<
LifeCycleObject
>
scoped_vector
{
watcher
.
NewLifeCycleObject
()
};
EXPECT_EQ
(
LC_CONSTRUCTED
,
watcher
.
life_cycle_state
());
EXPECT_TRUE
(
watcher
.
IsWatching
(
scoped_vector
.
back
()));
}
EXPECT_EQ
(
LC_DESTROYED
,
watcher
.
life_cycle_state
());
}
TEST
(
ScopedVectorTest
,
MoveConstruct
)
{
LifeCycleWatcher
watcher
;
EXPECT_EQ
(
LC_INITIAL
,
watcher
.
life_cycle_state
());
...
...
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