Przeglądaj źródła

convert to includable format

Sam Jaffe 2 lat temu
rodzic
commit
6356c89892

scope_guard.hpp → include/scope_guard/scope_guard.hpp


+ 0 - 90
scope_guard.t.h

@@ -1,90 +0,0 @@
-//
-//  scope_guard_tc.h
-//  scope_guard
-//
-//  Created by Sam Jaffe on 1/10/17.
-//
-#pragma once
-
-#include <cxxtest/TestSuite.h>
-#include <memory>
-
-#include "scope_guard.hpp"
-
-class scope_guard_TestSuite : public CxxTest::TestSuite {
-public:
-  using ptr = std::shared_ptr<int>;
-  static ptr make( int i ) { return std::make_shared<int>(i); }
-  
-#if __cplusplus > 201402L
-  struct example {
-    ~example() {
-      scope(success) { ++(*_p); };
-    }
-    ptr _p;
-  };
-#endif
-public:
-  void test_scope_exit_reset() const {
-    ptr p = make( 5 );
-    {
-      scope(exit) { p.reset(); };
-      TS_ASSERT( p );
-    }
-    TS_ASSERT( ! p );
-  }
-  
-#if __cplusplus > 201402L
-  void test_scope_failure_no_effect() const {
-    ptr p = make( 5 );
-    try {
-      scope(failure) { p.reset(); };
-    } catch (...) {
-    }
-    TS_ASSERT( p );
-  }
-
-  void test_scope_failure_on_exception() const {
-    ptr p = make( 5 );
-    try {
-      scope(failure) { p.reset(); };
-      throw 5;
-    } catch (...) {
-    }
-    TS_ASSERT( ! p );
-  }
-  
-  void test_scope_success_works() const {
-    ptr p = make( 5 );
-    try {
-      scope(success) { p.reset(); };
-    } catch (...) {
-    }
-    TS_ASSERT( ! p );
-  }
-  
-  void test_scope_success_on_exception_no_effect() const {
-    ptr p = make( 5 );
-    try {
-      scope(success) { p.reset(); };
-      throw 5;
-    } catch (...) {
-    }
-    TS_ASSERT( p );
-  }
-  
-  void test_multi_layer_scoping() const {
-    ptr p = make( 5 );
-    ptr r = p;
-    try {
-      scope(failure) { p.reset(); };
-      example ex { r };
-      throw 5;
-    } catch (...) {
-    }
-    TS_ASSERT( ! p );
-    TS_ASSERT_EQUALS( *r, 6 );
-  }
-
-#endif
-};

+ 225 - 70
scope_guard.xcodeproj/project.pbxproj

@@ -7,10 +7,19 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
-		CD3A75FA1E25B46F008C6DC2 /* scope_guard_tc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD3A75F81E25B46F008C6DC2 /* scope_guard_tc.cpp */; };
+		CDD215F429CCFB0100A4582C /* scope_guard.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD3A75F91E25B46F008C6DC2 /* scope_guard.cxx */; };
+		CDD215F529CCFB5000A4582C /* scope_guard in Headers */ = {isa = PBXBuildFile; fileRef = CDD215C429CCF9F000A4582C /* scope_guard */; settings = {ATTRIBUTES = (Public, ); }; };
+		CDD215F729CCFC0A00A4582C /* GoogleMock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDEC1DBE2351673F0091D9F2 /* GoogleMock.framework */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
+		CDD215EF29CCFA5000A4582C /* PBXContainerItemProxy */ = {
+			isa = PBXContainerItemProxy;
+			containerPortal = CD3DA4011D9B42F4001B53A0 /* Project object */;
+			proxyType = 1;
+			remoteGlobalIDString = CDD215D029CCFA1E00A4582C;
+			remoteInfo = scope_guard;
+		};
 		CDEC1DBD2351673F0091D9F2 /* PBXContainerItemProxy */ = {
 			isa = PBXContainerItemProxy;
 			containerPortal = CDEC1DB62351673F0091D9F2 /* GoogleMock.xcodeproj */;
@@ -41,72 +50,96 @@
 		};
 /* End PBXContainerItemProxy section */
 
-/* Begin PBXCopyFilesBuildPhase section */
-		CD3DA4071D9B42F4001B53A0 /* CopyFiles */ = {
-			isa = PBXCopyFilesBuildPhase;
-			buildActionMask = 2147483647;
-			dstPath = /usr/share/man/man1/;
-			dstSubfolderSpec = 0;
-			files = (
-			);
-			runOnlyForDeploymentPostprocessing = 1;
-		};
-/* End PBXCopyFilesBuildPhase section */
-
 /* Begin PBXFileReference section */
-		CD3A75F81E25B46F008C6DC2 /* scope_guard_tc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scope_guard_tc.cpp; sourceTree = "<group>"; };
-		CD3A75F91E25B46F008C6DC2 /* scope_guard.t.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scope_guard.t.h; sourceTree = "<group>"; };
-		CD3DA4091D9B42F4001B53A0 /* scope_guard_tc */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = scope_guard_tc; sourceTree = BUILT_PRODUCTS_DIR; };
-		CD3DA4131D9B4302001B53A0 /* scope_guard.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = scope_guard.hpp; sourceTree = "<group>"; };
+		CD3A75F91E25B46F008C6DC2 /* scope_guard.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scope_guard.cxx; sourceTree = "<group>"; };
+		CDD215C429CCF9F000A4582C /* scope_guard */ = {isa = PBXFileReference; lastKnownFileType = folder; name = scope_guard; path = include/scope_guard; sourceTree = "<group>"; };
+		CDD215CB29CCF9F600A4582C /* scope_guard.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = scope_guard.hpp; sourceTree = "<group>"; };
+		CDD215CC29CCFA1300A4582C /* xcode_gtest_helper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = xcode_gtest_helper.h; sourceTree = "<group>"; };
+		CDD215D129CCFA1E00A4582C /* libscope_guard.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libscope_guard.a; sourceTree = BUILT_PRODUCTS_DIR; };
+		CDD215EA29CCFA5000A4582C /* scope_guard-test.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "scope_guard-test.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
 		CDEC1DB62351673F0091D9F2 /* GoogleMock.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = GoogleMock.xcodeproj; path = "../../../../gmock-xcode-master/GoogleMock.xcodeproj"; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
-		CD3DA4061D9B42F4001B53A0 /* Frameworks */ = {
+		CDD215CF29CCFA1E00A4582C /* Frameworks */ = {
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
+		CDD215E729CCFA5000A4582C /* Frameworks */ = {
+			isa = PBXFrameworksBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				CDD215F729CCFC0A00A4582C /* GoogleMock.framework in Frameworks */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
 /* End PBXFrameworksBuildPhase section */
 
 /* Begin PBXGroup section */
 		CD3A75FB1E25B480008C6DC2 /* test */ = {
 			isa = PBXGroup;
 			children = (
-				CD3A75F91E25B46F008C6DC2 /* scope_guard.t.h */,
-				CD3A75F81E25B46F008C6DC2 /* scope_guard_tc.cpp */,
-			);
-			name = test;
-			sourceTree = "<group>";
-		};
-		CD3A75FC1E25B486008C6DC2 /* src */ = {
-			isa = PBXGroup;
-			children = (
-				CD3DA4131D9B4302001B53A0 /* scope_guard.hpp */,
+				CDD215CC29CCFA1300A4582C /* xcode_gtest_helper.h */,
+				CD3A75F91E25B46F008C6DC2 /* scope_guard.cxx */,
 			);
-			name = src;
+			path = test;
 			sourceTree = "<group>";
 		};
 		CD3DA4001D9B42F4001B53A0 = {
 			isa = PBXGroup;
 			children = (
 				CDEC1DB62351673F0091D9F2 /* GoogleMock.xcodeproj */,
-				CD3A75FC1E25B486008C6DC2 /* src */,
+				CDD215C429CCF9F000A4582C /* scope_guard */,
+				CDD215C929CCF9F600A4582C /* include */,
 				CD3A75FB1E25B480008C6DC2 /* test */,
+				CDD215EB29CCFA5000A4582C /* scope_guard-test */,
 				CD3DA40A1D9B42F4001B53A0 /* Products */,
+				CDD215F629CCFC0A00A4582C /* Frameworks */,
 			);
 			sourceTree = "<group>";
 		};
 		CD3DA40A1D9B42F4001B53A0 /* Products */ = {
 			isa = PBXGroup;
 			children = (
-				CD3DA4091D9B42F4001B53A0 /* scope_guard_tc */,
+				CDD215D129CCFA1E00A4582C /* libscope_guard.a */,
+				CDD215EA29CCFA5000A4582C /* scope_guard-test.xctest */,
 			);
 			name = Products;
 			sourceTree = "<group>";
 		};
+		CDD215C929CCF9F600A4582C /* include */ = {
+			isa = PBXGroup;
+			children = (
+				CDD215CA29CCF9F600A4582C /* scope_guard */,
+			);
+			path = include;
+			sourceTree = "<group>";
+		};
+		CDD215CA29CCF9F600A4582C /* scope_guard */ = {
+			isa = PBXGroup;
+			children = (
+				CDD215CB29CCF9F600A4582C /* scope_guard.hpp */,
+			);
+			path = scope_guard;
+			sourceTree = "<group>";
+		};
+		CDD215EB29CCFA5000A4582C /* scope_guard-test */ = {
+			isa = PBXGroup;
+			children = (
+			);
+			path = "scope_guard-test";
+			sourceTree = "<group>";
+		};
+		CDD215F629CCFC0A00A4582C /* Frameworks */ = {
+			isa = PBXGroup;
+			children = (
+			);
+			name = Frameworks;
+			sourceTree = "<group>";
+		};
 		CDEC1DB72351673F0091D9F2 /* Products */ = {
 			isa = PBXGroup;
 			children = (
@@ -120,24 +153,52 @@
 		};
 /* End PBXGroup section */
 
+/* Begin PBXHeadersBuildPhase section */
+		CDD215CD29CCFA1E00A4582C /* Headers */ = {
+			isa = PBXHeadersBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				CDD215F529CCFB5000A4582C /* scope_guard in Headers */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXHeadersBuildPhase section */
+
 /* Begin PBXNativeTarget section */
-		CD3DA4081D9B42F4001B53A0 /* scope_guard_tc */ = {
+		CDD215D029CCFA1E00A4582C /* scope_guard */ = {
 			isa = PBXNativeTarget;
-			buildConfigurationList = CD3DA4101D9B42F4001B53A0 /* Build configuration list for PBXNativeTarget "scope_guard_tc" */;
+			buildConfigurationList = CDD215D229CCFA1E00A4582C /* Build configuration list for PBXNativeTarget "scope_guard" */;
 			buildPhases = (
-				CD3A75FD1E25B4BE008C6DC2 /* ShellScript */,
-				CD3DA4051D9B42F4001B53A0 /* Sources */,
-				CD3DA4061D9B42F4001B53A0 /* Frameworks */,
-				CD3DA4071D9B42F4001B53A0 /* CopyFiles */,
+				CDD215CD29CCFA1E00A4582C /* Headers */,
+				CDD215CE29CCFA1E00A4582C /* Sources */,
+				CDD215CF29CCFA1E00A4582C /* Frameworks */,
 			);
 			buildRules = (
 			);
 			dependencies = (
 			);
-			name = scope_guard_tc;
+			name = scope_guard;
 			productName = scope_guard;
-			productReference = CD3DA4091D9B42F4001B53A0 /* scope_guard_tc */;
-			productType = "com.apple.product-type.tool";
+			productReference = CDD215D129CCFA1E00A4582C /* libscope_guard.a */;
+			productType = "com.apple.product-type.library.static";
+		};
+		CDD215E929CCFA5000A4582C /* scope_guard-test */ = {
+			isa = PBXNativeTarget;
+			buildConfigurationList = CDD215F129CCFA5000A4582C /* Build configuration list for PBXNativeTarget "scope_guard-test" */;
+			buildPhases = (
+				CDD215E629CCFA5000A4582C /* Sources */,
+				CDD215E729CCFA5000A4582C /* Frameworks */,
+				CDD215E829CCFA5000A4582C /* Resources */,
+			);
+			buildRules = (
+			);
+			dependencies = (
+				CDD215F029CCFA5000A4582C /* PBXTargetDependency */,
+			);
+			name = "scope_guard-test";
+			productName = "scope_guard-test";
+			productReference = CDD215EA29CCFA5000A4582C /* scope_guard-test.xctest */;
+			productType = "com.apple.product-type.bundle.unit-test";
 		};
 /* End PBXNativeTarget section */
 
@@ -145,11 +206,17 @@
 		CD3DA4011D9B42F4001B53A0 /* Project object */ = {
 			isa = PBXProject;
 			attributes = {
+				LastSwiftUpdateCheck = 1340;
 				LastUpgradeCheck = 1230;
 				ORGANIZATIONNAME = "Sam Jaffe";
 				TargetAttributes = {
-					CD3DA4081D9B42F4001B53A0 = {
-						CreatedOnToolsVersion = 7.2.1;
+					CDD215D029CCFA1E00A4582C = {
+						CreatedOnToolsVersion = 13.4.1;
+						ProvisioningStyle = Automatic;
+					};
+					CDD215E929CCFA5000A4582C = {
+						CreatedOnToolsVersion = 13.4.1;
+						ProvisioningStyle = Automatic;
 					};
 				};
 			};
@@ -172,7 +239,8 @@
 			);
 			projectRoot = "";
 			targets = (
-				CD3DA4081D9B42F4001B53A0 /* scope_guard_tc */,
+				CDD215D029CCFA1E00A4582C /* scope_guard */,
+				CDD215E929CCFA5000A4582C /* scope_guard-test */,
 			);
 		};
 /* End PBXProject section */
@@ -208,42 +276,49 @@
 		};
 /* End PBXReferenceProxy section */
 
-/* Begin PBXShellScriptBuildPhase section */
-		CD3A75FD1E25B4BE008C6DC2 /* ShellScript */ = {
-			isa = PBXShellScriptBuildPhase;
+/* Begin PBXResourcesBuildPhase section */
+		CDD215E829CCFA5000A4582C /* Resources */ = {
+			isa = PBXResourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
 			);
-			inputPaths = (
-				"$(SRCROOT)/scope_guard.t.h",
-			);
-			outputPaths = (
-				"$(SRCROOT)/scope_guard_tc.cpp",
-			);
 			runOnlyForDeploymentPostprocessing = 0;
-			shellPath = /bin/sh;
-			shellScript = "cxxtestgen --error-printer -o scope_guard_tc.cpp scope_guard.t.h";
 		};
-/* End PBXShellScriptBuildPhase section */
+/* End PBXResourcesBuildPhase section */
 
 /* Begin PBXSourcesBuildPhase section */
-		CD3DA4051D9B42F4001B53A0 /* Sources */ = {
+		CDD215CE29CCFA1E00A4582C /* Sources */ = {
+			isa = PBXSourcesBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+		CDD215E629CCFA5000A4582C /* Sources */ = {
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
-				CD3A75FA1E25B46F008C6DC2 /* scope_guard_tc.cpp in Sources */,
+				CDD215F429CCFB0100A4582C /* scope_guard.cxx in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
 /* End PBXSourcesBuildPhase section */
 
+/* Begin PBXTargetDependency section */
+		CDD215F029CCFA5000A4582C /* PBXTargetDependency */ = {
+			isa = PBXTargetDependency;
+			target = CDD215D029CCFA1E00A4582C /* scope_guard */;
+			targetProxy = CDD215EF29CCFA5000A4582C /* PBXContainerItemProxy */;
+		};
+/* End PBXTargetDependency section */
+
 /* Begin XCBuildConfiguration section */
 		CD3DA40E1D9B42F4001B53A0 /* Debug */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
 				ALWAYS_SEARCH_USER_PATHS = NO;
 				CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
-				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+				CLANG_CXX_LANGUAGE_STANDARD = "c++17";
 				CLANG_CXX_LIBRARY = "libc++";
 				CLANG_ENABLE_MODULES = YES;
 				CLANG_ENABLE_OBJC_ARC = YES;
@@ -290,6 +365,7 @@
 				MTL_ENABLE_DEBUG_INFO = YES;
 				ONLY_ACTIVE_ARCH = YES;
 				SDKROOT = macosx;
+				SYSTEM_HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/include $(BUILD_TARGET_DIR)/usr/local/include";
 			};
 			name = Debug;
 		};
@@ -298,7 +374,7 @@
 			buildSettings = {
 				ALWAYS_SEARCH_USER_PATHS = NO;
 				CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
-				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+				CLANG_CXX_LANGUAGE_STANDARD = "c++17";
 				CLANG_CXX_LIBRARY = "libc++";
 				CLANG_ENABLE_MODULES = YES;
 				CLANG_ENABLE_OBJC_ARC = YES;
@@ -338,26 +414,96 @@
 				MACOSX_DEPLOYMENT_TARGET = 10.10;
 				MTL_ENABLE_DEBUG_INFO = NO;
 				SDKROOT = macosx;
+				SYSTEM_HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/include $(BUILD_TARGET_DIR)/usr/local/include";
 			};
 			name = Release;
 		};
-		CD3DA4111D9B42F4001B53A0 /* Debug */ = {
+		CDD215D329CCFA1E00A4582C /* Debug */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
-				CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
-				CODE_SIGN_IDENTITY = "-";
-				HEADER_SEARCH_PATHS = /usr/local/include/;
+				CLANG_ANALYZER_NONNULL = YES;
+				CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
+				CLANG_ENABLE_OBJC_WEAK = YES;
+				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+				CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
+				CODE_SIGN_STYLE = Automatic;
+				EXECUTABLE_PREFIX = lib;
+				GCC_C_LANGUAGE_STANDARD = gnu11;
+				MACOSX_DEPLOYMENT_TARGET = 12.0;
+				MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
+				MTL_FAST_MATH = YES;
 				PRODUCT_NAME = "$(TARGET_NAME)";
+				SKIP_INSTALL = YES;
 			};
 			name = Debug;
 		};
-		CD3DA4121D9B42F4001B53A0 /* Release */ = {
+		CDD215D429CCFA1E00A4582C /* Release */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
-				CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
-				CODE_SIGN_IDENTITY = "-";
-				HEADER_SEARCH_PATHS = /usr/local/include/;
+				CLANG_ANALYZER_NONNULL = YES;
+				CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
+				CLANG_ENABLE_OBJC_WEAK = YES;
+				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+				CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
+				CODE_SIGN_STYLE = Automatic;
+				EXECUTABLE_PREFIX = lib;
+				GCC_C_LANGUAGE_STANDARD = gnu11;
+				MACOSX_DEPLOYMENT_TARGET = 12.0;
+				MTL_FAST_MATH = YES;
+				PRODUCT_NAME = "$(TARGET_NAME)";
+				SKIP_INSTALL = YES;
+			};
+			name = Release;
+		};
+		CDD215F229CCFA5000A4582C /* Debug */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				CLANG_ANALYZER_NONNULL = YES;
+				CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
+				CLANG_ENABLE_OBJC_WEAK = YES;
+				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+				CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
+				CODE_SIGN_STYLE = Automatic;
+				CURRENT_PROJECT_VERSION = 1;
+				GCC_C_LANGUAGE_STANDARD = gnu11;
+				GENERATE_INFOPLIST_FILE = YES;
+				MACOSX_DEPLOYMENT_TARGET = 12.0;
+				MARKETING_VERSION = 1.0;
+				MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
+				MTL_FAST_MATH = YES;
+				PRODUCT_BUNDLE_IDENTIFIER = "leumasjaffe.scope-guard-test";
+				PRODUCT_NAME = "$(TARGET_NAME)";
+				SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
+				SWIFT_EMIT_LOC_STRINGS = NO;
+				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+				SWIFT_VERSION = 5.0;
+			};
+			name = Debug;
+		};
+		CDD215F329CCFA5000A4582C /* Release */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				CLANG_ANALYZER_NONNULL = YES;
+				CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
+				CLANG_ENABLE_OBJC_WEAK = YES;
+				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+				CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
+				CODE_SIGN_STYLE = Automatic;
+				CURRENT_PROJECT_VERSION = 1;
+				GCC_C_LANGUAGE_STANDARD = gnu11;
+				GENERATE_INFOPLIST_FILE = YES;
+				MACOSX_DEPLOYMENT_TARGET = 12.0;
+				MARKETING_VERSION = 1.0;
+				MTL_FAST_MATH = YES;
+				PRODUCT_BUNDLE_IDENTIFIER = "leumasjaffe.scope-guard-test";
 				PRODUCT_NAME = "$(TARGET_NAME)";
+				SWIFT_EMIT_LOC_STRINGS = NO;
+				SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
+				SWIFT_VERSION = 5.0;
 			};
 			name = Release;
 		};
@@ -373,11 +519,20 @@
 			defaultConfigurationIsVisible = 0;
 			defaultConfigurationName = Release;
 		};
-		CD3DA4101D9B42F4001B53A0 /* Build configuration list for PBXNativeTarget "scope_guard_tc" */ = {
+		CDD215D229CCFA1E00A4582C /* Build configuration list for PBXNativeTarget "scope_guard" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				CDD215D329CCFA1E00A4582C /* Debug */,
+				CDD215D429CCFA1E00A4582C /* Release */,
+			);
+			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Release;
+		};
+		CDD215F129CCFA5000A4582C /* Build configuration list for PBXNativeTarget "scope_guard-test" */ = {
 			isa = XCConfigurationList;
 			buildConfigurations = (
-				CD3DA4111D9B42F4001B53A0 /* Debug */,
-				CD3DA4121D9B42F4001B53A0 /* Release */,
+				CDD215F229CCFA5000A4582C /* Debug */,
+				CDD215F329CCFA5000A4582C /* Release */,
 			);
 			defaultConfigurationIsVisible = 0;
 			defaultConfigurationName = Release;

+ 78 - 0
scope_guard.xcodeproj/xcshareddata/xcschemes/scope_guard.xcscheme

@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+   LastUpgradeVersion = "1340"
+   version = "1.3">
+   <BuildAction
+      parallelizeBuildables = "YES"
+      buildImplicitDependencies = "YES">
+      <BuildActionEntries>
+         <BuildActionEntry
+            buildForTesting = "YES"
+            buildForRunning = "YES"
+            buildForProfiling = "YES"
+            buildForArchiving = "YES"
+            buildForAnalyzing = "YES">
+            <BuildableReference
+               BuildableIdentifier = "primary"
+               BlueprintIdentifier = "CDD215D029CCFA1E00A4582C"
+               BuildableName = "libscope_guard.a"
+               BlueprintName = "scope_guard"
+               ReferencedContainer = "container:scope_guard.xcodeproj">
+            </BuildableReference>
+         </BuildActionEntry>
+      </BuildActionEntries>
+   </BuildAction>
+   <TestAction
+      buildConfiguration = "Debug"
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      shouldUseLaunchSchemeArgsEnv = "YES"
+      codeCoverageEnabled = "YES">
+      <Testables>
+         <TestableReference
+            skipped = "NO">
+            <BuildableReference
+               BuildableIdentifier = "primary"
+               BlueprintIdentifier = "CDD215E929CCFA5000A4582C"
+               BuildableName = "scope_guard-test.xctest"
+               BlueprintName = "scope_guard-test"
+               ReferencedContainer = "container:scope_guard.xcodeproj">
+            </BuildableReference>
+         </TestableReference>
+      </Testables>
+   </TestAction>
+   <LaunchAction
+      buildConfiguration = "Debug"
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      launchStyle = "0"
+      useCustomWorkingDirectory = "NO"
+      ignoresPersistentStateOnLaunch = "NO"
+      debugDocumentVersioning = "YES"
+      debugServiceExtension = "internal"
+      allowLocationSimulation = "YES">
+   </LaunchAction>
+   <ProfileAction
+      buildConfiguration = "Release"
+      shouldUseLaunchSchemeArgsEnv = "YES"
+      savedToolIdentifier = ""
+      useCustomWorkingDirectory = "NO"
+      debugDocumentVersioning = "YES">
+      <MacroExpansion>
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "CDD215D029CCFA1E00A4582C"
+            BuildableName = "libscope_guard.a"
+            BlueprintName = "scope_guard"
+            ReferencedContainer = "container:scope_guard.xcodeproj">
+         </BuildableReference>
+      </MacroExpansion>
+   </ProfileAction>
+   <AnalyzeAction
+      buildConfiguration = "Debug">
+   </AnalyzeAction>
+   <ArchiveAction
+      buildConfiguration = "Release"
+      revealArchiveInOrganizer = "YES">
+   </ArchiveAction>
+</Scheme>

+ 89 - 0
test/scope_guard.cxx

@@ -0,0 +1,89 @@
+//
+//  scope_guard_tc.h
+//  scope_guard
+//
+//  Created by Sam Jaffe on 1/10/17.
+//
+#include <memory>
+
+#include <scope_guard/scope_guard.hpp>
+
+#include "xcode_gtest_helper.h"
+
+using testing::NotNull;
+using testing::IsNull;
+
+using ptr = std::shared_ptr<int>;
+
+ptr make( int i ) { return std::make_shared<int>(i); }
+
+#if __cplusplus > 201402L
+struct example {
+  ~example() {
+    scope(success) { ++(*_p); };
+  }
+  ptr _p;
+};
+#endif
+
+TEST(Scope, ExitCallsFunction) {
+  ptr p = make( 5 );
+  {
+    scope(exit) { p.reset(); };
+    EXPECT_THAT(p, NotNull());
+  }
+  EXPECT_THAT(p, IsNull());
+}
+
+#if __cplusplus > 201402L
+TEST(ScopeFailure, NoOpOnNoexcept) {
+  ptr p = make( 5 );
+  try {
+    scope(failure) { p.reset(); };
+  } catch (...) {
+  }
+  EXPECT_THAT(p, NotNull());
+}
+
+TEST(ScopeFailure, RunsOnException) {
+  ptr p = make( 5 );
+  try {
+    scope(failure) { p.reset(); };
+    throw 5;
+  } catch (...) {
+  }
+  EXPECT_THAT(p, IsNull());
+}
+
+TEST(ScopeSuccess, RunsOnNoexcept) {
+  ptr p = make( 5 );
+  try {
+    scope(success) { p.reset(); };
+  } catch (...) {
+  }
+  EXPECT_THAT(p, IsNull());
+}
+
+TEST(ScopeSuccess, NoOpOnException) {
+  ptr p = make( 5 );
+  try {
+    scope(success) { p.reset(); };
+    throw 5;
+  } catch (...) {
+  }
+  EXPECT_THAT(p, NotNull());
+}
+
+TEST(Scope, CanLayer) {
+  ptr p = make( 5 );
+  ptr r = p;
+  try {
+    scope(failure) { p.reset(); };
+    example ex { r };
+    throw 5;
+  } catch (...) {
+  }
+  EXPECT_THAT(p, IsNull());
+  EXPECT_EQ(*r, 6);
+}
+#endif

+ 38 - 0
test/xcode_gtest_helper.h

@@ -0,0 +1,38 @@
+//
+//  xcode_gtest_helper.h
+//
+//  Created by Sam Jaffe on 11/25/20.
+//  Copyright © 2020 Sam Jaffe. All rights reserved.
+//
+
+#pragma once
+
+#if defined(__APPLE__)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wquoted-include-in-framework-header"
+#pragma clang diagnostic ignored "-Wcomma"
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#pragma clang diagnostic pop
+
+#if defined(TARGET_OS_OSX)
+// This is a hack to allow XCode to properly display failures when running
+// unit tests.
+#undef EXPECT_THAT
+#define EXPECT_THAT ASSERT_THAT
+#undef EXPECT_THROW
+#define EXPECT_THROW ASSERT_THROW
+#undef EXPECT_ANY_THROW
+#define EXPECT_ANY_THROW ASSERT_ANY_THROW
+#undef EXPECT_NO_THROW
+#define EXPECT_NO_THROW ASSERT_NO_THROW
+#undef EXPECT_TRUE
+#define EXPECT_TRUE ASSERT_TRUE
+#undef EXPECT_FALSE
+#define EXPECT_FALSE ASSERT_FALSE
+
+#endif
+#endif