From 56ccba6d09ceeabb32974ebe572db516627f3fca Mon Sep 17 00:00:00 2001 From: syntheticpp Date: Tue, 14 Feb 2006 11:48:53 +0000 Subject: [PATCH] use RefToValue.h, add dismiss for the ref guard git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@529 7ec92016-0320-0410-acc4-a06ded1c099a --- test/ScopeGuard/main.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/ScopeGuard/main.cpp b/test/ScopeGuard/main.cpp index ed83c6e..93785dc 100755 --- a/test/ScopeGuard/main.cpp +++ b/test/ScopeGuard/main.cpp @@ -13,8 +13,9 @@ // $Header: - #include +#include + #include #include #include @@ -22,7 +23,7 @@ void Decrement(int& x) { - --x; + --x; } struct UserDatabase @@ -37,7 +38,7 @@ class User { public: User(UserDatabase* db) : fCount(0), pDB_(db) - {} + {} std::string GetName(); @@ -78,10 +79,10 @@ void User::AddFriendGuarded(User& newFriend) fCount++; Loki::ScopeGuard guardRef = Loki::MakeGuard(Decrement, Loki::ByRef(fCount)); - (void) guardRef; pDB_->AddFriend(GetName(), newFriend.GetName()); guard.Dismiss(); + guardRef.Dismiss(); } @@ -95,12 +96,12 @@ int main() try{ u1.AddFriend(u2); } catch (...){} std::cout << "u1 countFriends: " << u1.countFriends() << "\n"; - std::cout << "u1 fCount : " << u1.fCount << "\n"; + std::cout << "u1 fCount : " << u1.fCount << "\n"; try{ u2.AddFriendGuarded(u1); } catch (...){} std::cout << "u2 countFriends: " << u2.countFriends() << "\n"; - std::cout << "u2 fCount : " << u2.fCount << "\n"; + std::cout << "u2 fCount : " << u2.fCount << "\n"; #if defined(__BORLANDC__) || defined(_MSC_VER) system("PAUSE");