浏览代码

Add clang-format support.

Sam Jaffe 5 年之前
父节点
当前提交
388e3343e6
共有 4 个文件被更改,包括 130 次插入28 次删除
  1. 108 0
      .clang-format
  2. 9 16
      include/opaque_typedef/arithmetic.hpp
  3. 3 5
      include/opaque_typedef/comparable.hpp
  4. 10 7
      include/opaque_typedef/opaque_typedef.hpp

+ 108 - 0
.clang-format

@@ -0,0 +1,108 @@
+---
+Language:        Cpp
+# BasedOnStyle:  LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Right
+AlignOperands:   true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: true
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: true
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:   
+  AfterClass:      false
+  AfterControlStatement: false
+  AfterEnum:       false
+  AfterFunction:   false
+  AfterNamespace:  false
+  AfterObjCDeclaration: false
+  AfterStruct:     false
+  AfterUnion:      false
+  BeforeCatch:     false
+  BeforeElse:      false
+  IndentBraces:    false
+  SplitEmptyFunction: true
+  SplitEmptyRecord: true
+  SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Attach
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeColon
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: true
+ColumnLimit:     80
+CommentPragmas:  '^ IWYU pragma:'
+CompactNamespaces: true
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+DisableFormat:   false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: false
+ForEachMacros:   
+  - foreach
+  - Q_FOREACH
+  - BOOST_FOREACH
+IncludeCategories: 
+  - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
+    Priority:        2
+  - Regex:           '^(<|"(gtest|gmock|isl|json)/)'
+    Priority:        3
+  - Regex:           '.*'
+    Priority:        1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+IndentWidth:     2
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd:   ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: All
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakAssignment: 2
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerAlignment: Middle
+ReflowComments:  true
+SortIncludes:    true
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles:  false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard:        Cpp11
+TabWidth:        8
+UseTab:          Never
+...
+

+ 9 - 16
include/opaque_typedef/arithmetic.hpp

@@ -1,8 +1,7 @@
 #pragma once
 
 namespace types {
-  template <typename Self>
-  struct Incrementable {
+  template <typename Self> struct Incrementable {
     friend Self operator++(Self & self, int) {
       Self copy = self;
       self = Self(self.get() + 1);
@@ -13,8 +12,7 @@ namespace types {
     }
   };
 
-  template <typename Self>
-  struct Decrementable {
+  template <typename Self> struct Decrementable {
     friend Self operator--(Self & self, int) {
       Self copy = self;
       self = Self(self.get() - 1);
@@ -25,30 +23,25 @@ namespace types {
     }
   };
 
-  template <typename Self>
-  struct Addable {
+  template <typename Self> struct Addable {
     friend Self operator+(Self const & lhs, Self const & rhs) {
       return Self(lhs.get() + rhs.get());
     }
   };
-    
-  template <typename Self>
-  struct Arithmetic : Addable<Self> {
-    friend Self operator-(Self const & self) {
-      return Self(-self.get());
-    }
-    
+
+  template <typename Self> struct Arithmetic : Addable<Self> {
+    friend Self operator-(Self const & self) { return Self(-self.get()); }
+
     friend Self operator-(Self const & lhs, Self const & rhs) {
       return Self(lhs.get() - rhs.get());
     }
   };
 
-  template <typename Self>
-  struct Numeric : Arithmetic<Self> {
+  template <typename Self> struct Numeric : Arithmetic<Self> {
     friend Self operator*(Self const & lhs, Self const & rhs) {
       return Self(lhs.get() * rhs.get());
     }
-    
+
     friend Self operator/(Self const & lhs, Self const & rhs) {
       return Self(lhs.get() / rhs.get());
     }

+ 3 - 5
include/opaque_typedef/comparable.hpp

@@ -1,8 +1,7 @@
 #pragma once
 
 namespace types {
-  template <typename Self>
-  struct EqualityComparable {
+  template <typename Self> struct EqualityComparable {
     friend bool operator==(Self const & lhs, Self const & rhs) {
       return lhs.get() == rhs.get();
     }
@@ -10,9 +9,8 @@ namespace types {
       return !(lhs == rhs);
     }
   };
-  
-  template <typename Self>
-  struct Comparable : EqualityComparable<Self> {
+
+  template <typename Self> struct Comparable : EqualityComparable<Self> {
     friend bool operator<(Self const & lhs, Self const & rhs) {
       return lhs.get() < rhs.get();
     }

+ 10 - 7
include/opaque_typedef/opaque_typedef.hpp

@@ -2,7 +2,8 @@
 //  opaque_typedef.hpp
 //  opaque-type
 //
-//  Inspired by https://foonathan.github.io/blog/2016/10/19/strong-typedefs.html and others
+//  Inspired by https://foonathan.github.io/blog/2016/10/19/strong-typedefs.html
+//  and others
 //
 //  Created by Sam Jaffe on 8/16/16.
 //
@@ -16,18 +17,20 @@
 
 namespace types {
   template <typename Base, typename Tag, template <typename> class... Skills>
-  class opaque_typedef : public Skills<opaque_typedef<Base, Tag, Skills...>>... {
+  class opaque_typedef
+      : public Skills<opaque_typedef<Base, Tag, Skills...>>... {
   private:
     Base value_;
-    
+
   public:
     opaque_typedef() = default;
-    explicit opaque_typedef(Base const & value) : value_(value) {};
-    explicit opaque_typedef(Base && value) : value_(std::forward<Base>(value)) {};
+    explicit opaque_typedef(Base const & value) : value_(value){};
+    explicit opaque_typedef(Base && value)
+        : value_(std::forward<Base>(value)){};
     template <typename B, typename T, template <typename> class... S>
     opaque_typedef(opaque_typedef<B, T, S...> const & other);
-    
+
     Base const & get() const { return value_; }
     explicit operator Base const &() const { return value_; }
-  };  
+  };
 }