diff --git a/include/grpc++/auth_context.h b/include/grpc++/auth_context.h index 394cb34ec41..3373bae9572 100644 --- a/include/grpc++/auth_context.h +++ b/include/grpc++/auth_context.h @@ -70,7 +70,6 @@ class AuthContext { size_t index_; const char* name_; }; - typedef PropertyIterator const_iterator; virtual ~AuthContext() {} @@ -84,8 +83,8 @@ class AuthContext { const grpc::string& name) const = 0; // Iteration over all the properties. - virtual const_iterator begin() const = 0; - virtual const_iterator end() const = 0; + virtual PropertyIterator begin() const = 0; + virtual PropertyIterator end() const = 0; }; } // namespace grpc diff --git a/src/cpp/common/secure_auth_context.cc b/src/cpp/common/secure_auth_context.cc index 53b940f108e..3f805790f38 100644 --- a/src/cpp/common/secure_auth_context.cc +++ b/src/cpp/common/secure_auth_context.cc @@ -124,7 +124,7 @@ const AuthContext::Property AuthContext::PropertyIterator::operator*() { grpc::string(property_->value, property_->value_length)); } -SecureAuthContext::const_iterator SecureAuthContext::begin() const { +AuthContext::PropertyIterator SecureAuthContext::begin() const { if (ctx_) { grpc_auth_property_iterator iter = grpc_auth_context_property_iterator(ctx_); @@ -136,7 +136,7 @@ SecureAuthContext::const_iterator SecureAuthContext::begin() const { } } -SecureAuthContext::const_iterator SecureAuthContext::end() const { +AuthContext::PropertyIterator SecureAuthContext::end() const { return AuthContext::PropertyIterator(); } diff --git a/src/cpp/common/secure_auth_context.h b/src/cpp/common/secure_auth_context.h index 9ea4eb1b5ca..aa0f6a0db70 100644 --- a/src/cpp/common/secure_auth_context.h +++ b/src/cpp/common/secure_auth_context.h @@ -53,9 +53,9 @@ class SecureAuthContext GRPC_FINAL : public AuthContext { std::vector FindPropertyValues(const grpc::string& name) const GRPC_OVERRIDE; - const_iterator begin() const GRPC_OVERRIDE; + PropertyIterator begin() const GRPC_OVERRIDE; - const_iterator end() const GRPC_OVERRIDE; + PropertyIterator end() const GRPC_OVERRIDE; private: grpc_auth_context* ctx_; diff --git a/test/cpp/common/secure_auth_context_test.cc b/test/cpp/common/secure_auth_context_test.cc index 6cc271f3a72..c8863e33c2c 100644 --- a/test/cpp/common/secure_auth_context_test.cc +++ b/test/cpp/common/secure_auth_context_test.cc @@ -77,7 +77,7 @@ TEST_F(SecureAuthContextTest, Iterators) { ctx->peer_identity_property_name = ctx->properties[0].name; SecureAuthContext context(ctx); - AuthContext::const_iterator iter = context.begin(); + AuthContext::PropertyIterator iter = context.begin(); EXPECT_TRUE(context.end() != iter); AuthContext::Property p0 = *iter; ++iter; @@ -92,6 +92,26 @@ TEST_F(SecureAuthContextTest, Iterators) { EXPECT_EQ("bar", p2.second); ++iter; EXPECT_EQ(context.end(), iter); + // Range-based for loop test. + int i = 0; + for (const AuthContext::Property p : context) { + switch (i++) { + case 0: + EXPECT_EQ("name", p.first); + EXPECT_EQ("chapi", p.second); + break; + case 1: + EXPECT_EQ("name", p.first); + EXPECT_EQ("chapo", p.second); + break; + case 2: + EXPECT_EQ("foo", p.first); + EXPECT_EQ("bar", p.second); + break; + default: + EXPECT_TRUE(0); + } + } } } // namespace