├── .dep.inc ├── .gitignore ├── .gitmodules ├── Makefile ├── README.md ├── build ├── Debug │ └── LLVM │ │ └── Clang-Linux-x86 │ │ └── main.o.d └── Release │ └── LLVM │ └── Clang-Linux-x86 │ ├── main.o │ └── main.o.d ├── functors.hpp ├── main.cpp ├── nbproject ├── Makefile-Debug.mk ├── Makefile-Release.mk ├── Makefile-impl.mk ├── Makefile-variables.mk ├── Package-Debug.bash ├── Package-Release.bash ├── configurations.xml ├── private │ ├── Makefile-variables.mk │ ├── configurations.xml │ ├── launcher.properties │ └── private.xml └── project.xml ├── operand.hpp ├── operator_proxy.hpp ├── operators.hpp └── polyop.hpp /.dep.inc: -------------------------------------------------------------------------------- 1 | # This code depends on make tool being used 2 | DEPFILES=$(wildcard $(addsuffix .d, ${OBJECTFILES})) 3 | ifneq (${DEPFILES},) 4 | include ${DEPFILES} 5 | endif 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /dist/ -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Turbo"] 2 | path = Turbo 3 | url = https://github.com/Manu343726/Turbo.git 4 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # There exist several targets which are by default empty and which can be 3 | # used for execution of your targets. These targets are usually executed 4 | # before and after some main targets. They are: 5 | # 6 | # .build-pre: called before 'build' target 7 | # .build-post: called after 'build' target 8 | # .clean-pre: called before 'clean' target 9 | # .clean-post: called after 'clean' target 10 | # .clobber-pre: called before 'clobber' target 11 | # .clobber-post: called after 'clobber' target 12 | # .all-pre: called before 'all' target 13 | # .all-post: called after 'all' target 14 | # .help-pre: called before 'help' target 15 | # .help-post: called after 'help' target 16 | # 17 | # Targets beginning with '.' are not intended to be called on their own. 18 | # 19 | # Main targets can be executed directly, and they are: 20 | # 21 | # build build a specific configuration 22 | # clean remove built files from a configuration 23 | # clobber remove all built files 24 | # all build all configurations 25 | # help print help mesage 26 | # 27 | # Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and 28 | # .help-impl are implemented in nbproject/makefile-impl.mk. 29 | # 30 | # Available make variables: 31 | # 32 | # CND_BASEDIR base directory for relative paths 33 | # CND_DISTDIR default top distribution directory (build artifacts) 34 | # CND_BUILDDIR default top build directory (object files, ...) 35 | # CONF name of current configuration 36 | # CND_PLATFORM_${CONF} platform name (current configuration) 37 | # CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration) 38 | # CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration) 39 | # CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration) 40 | # CND_PACKAGE_DIR_${CONF} directory of package (current configuration) 41 | # CND_PACKAGE_NAME_${CONF} name of package (current configuration) 42 | # CND_PACKAGE_PATH_${CONF} path to package (current configuration) 43 | # 44 | # NOCDDL 45 | 46 | 47 | # Environment 48 | MKDIR=mkdir 49 | CP=cp 50 | CCADMIN=CCadmin 51 | 52 | 53 | # build 54 | build: .build-post 55 | 56 | .build-pre: 57 | # Add your pre 'build' code here... 58 | 59 | .build-post: .build-impl 60 | # Add your post 'build' code here... 61 | 62 | 63 | # clean 64 | clean: .clean-post 65 | 66 | .clean-pre: 67 | # Add your pre 'clean' code here... 68 | 69 | .clean-post: .clean-impl 70 | # Add your post 'clean' code here... 71 | 72 | 73 | # clobber 74 | clobber: .clobber-post 75 | 76 | .clobber-pre: 77 | # Add your pre 'clobber' code here... 78 | 79 | .clobber-post: .clobber-impl 80 | # Add your post 'clobber' code here... 81 | 82 | 83 | # all 84 | all: .all-post 85 | 86 | .all-pre: 87 | # Add your pre 'all' code here... 88 | 89 | .all-post: .all-impl 90 | # Add your post 'all' code here... 91 | 92 | 93 | # build tests 94 | build-tests: .build-tests-post 95 | 96 | .build-tests-pre: 97 | # Add your pre 'build-tests' code here... 98 | 99 | .build-tests-post: .build-tests-impl 100 | # Add your post 'build-tests' code here... 101 | 102 | 103 | # run tests 104 | test: .test-post 105 | 106 | .test-pre: build-tests 107 | # Add your pre 'test' code here... 108 | 109 | .test-post: .test-impl 110 | # Add your post 'test' code here... 111 | 112 | 113 | # help 114 | help: .help-post 115 | 116 | .help-pre: 117 | # Add your pre 'help' code here... 118 | 119 | .help-post: .help-impl 120 | # Add your post 'help' code here... 121 | 122 | 123 | 124 | # include project implementation makefile 125 | include nbproject/Makefile-impl.mk 126 | 127 | # include project make variables 128 | include nbproject/Makefile-variables.mk 129 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Polyop 2 | ====== 3 | 4 | Overridable universal operator overloading for C++14 5 | 6 | 7 | ## What is Polyop? 8 | 9 | C++ supports operator overloading, allowing the users to specify custom semantics for that operators when they are used together with user defined types. For example: 10 | 11 | ``` cpp 12 | 13 | struct foo{}; 14 | 15 | std::ostream& operator<<( std::ostream& os , const foo& ) 16 | { 17 | return os << "a foo!"; 18 | } 19 | ``` 20 | 21 | That specification works using function overloads, so **that semantics are fixed and unique**. Of course all C++ basic and library types have their own operator overloads, for example `1 + 1` is allowed since there is a `operator+(int,int)` overload. 22 | 23 | But, **what if that default operator semantics don't meet our requirements?** Thats where Polyop kicks in. 24 | 25 | Consider the common floating-point comparison issue: 26 | 27 | ``` cpp 28 | float a = 2.0f , b = 3.0f 29 | 30 | assert( a + a - b == 1.0f ); 31 | ``` 32 | 33 | Floating-point arithmetic suffers from precission errors due to mantissa rounding on certain operations (Primarily additions and subtractions), so in the example above the assertion could fail even it that condition seems trivial. In fact C/C++ compilers never optimize floating-point arithmetic expressions since floating-point operations are not commutative, associative, nor pure (A function is considered pure if an application always return the same result for the same arguments. Thats not entirely true for floating-point ops). 34 | 35 | So, as you can see, **the default semantics of the equality operator don't work well on some contexts**. You could write a fp-aware comparison function ala Java, like this: 36 | 37 | ``` cpp 38 | bool compare( float x , float y ) 39 | { 40 | return std::abs( x - y ) < 0.00001f; 41 | } 42 | ``` 43 | 44 | But that may break C++ readability, since in one situation you use `compare()` and `==` in others. 45 | **What Polyop does is to provide a way to customize the default behavior of C++ operators for different contexts**: 46 | 47 | ``` cpp 48 | assert( pop::wrap( a + a - b ) == 1.0f ); 49 | ``` 50 | 51 | Now the assertion never fails since the user provided a fp-aware semantic for `operator==()` using Polyop. 52 | 53 | ## How it works? 54 | 55 | Since C++ operators work through overloading, we need a custom datatype to change the semantics of an operator. If you want to change the semantics of an existing type with its own operator overload you have to wrap it in a custom type. 56 | The function `pop::wrap()` takes an operand (lvalue or rvalue) and efficiently stores it to be used as an operand of a Polyop operator. In other words, `pop::wrap()` triggers the usage of a Polyop operator instead of the default C++ one. 57 | 58 | ``` cpp 59 | int a , b; 60 | 61 | a == b; //Calls operator==(int,int) 62 | cpp::wrap(a) == b; //Calls custom Polyop operator== 63 | ``` 64 | 65 | Polyop operators are evaluated lazily by default, and they are manipulable entities, allowing you to manipulate the expression before the call is even applied, do partial operator application, or even store the operator expression: 66 | 67 | ``` cpp 68 | int a , b; 69 | 70 | auto comp = pop::wrap( a ) == b; //The comparison is not executed but stored in comp. 71 | bool r1 = comp(); //Call the comparison. 72 | auto expression = __ == __; //Store a naked comparison expression 73 | auto partial_call = expression( a ); //Pass the first argumment to the expression 74 | bool r2 = partial_call( b ); //Pass the last argumment to the expression (Then calling the operator). 75 | 76 | bool lex_result = (pop::wrap( a ) == b ).context( lexicographical ); /Applies a "lexicographical" comparison context. 77 | 78 | ``` 79 | 80 | ### Ok, how it *really* works? 81 | 82 | Using the `pop::operand` template Polyop wraps all the binary operators which request for a Polyop operator call, that is, any operator which one of its 83 | operands is a `pop::operand` instance. Then a proxy is generated storing the call signature and the call arguments. Is that proxy what a call like `pop::wrap(1) + 2` returns. 84 | Then the proxy is called using the specified context (`pop::default_operator` by default) or an implicit call is done due to a implicit conversion from the operator expression to 85 | the result type. 86 | 87 | The user context customization works through *operator dispatchers*. An operator dispatcher is a particular overload of the required operator which specifies the action to be done 88 | when the corresponding Polyop operator is called: 89 | 90 | ``` cpp 91 | 92 | auto operator==(void(float,float) , float_context_tag ) 93 | { 94 | return []( float x , float y ) 95 | { 96 | return /* some floating-point aware comparison */; 97 | }; 98 | } 99 | ``` 100 | The idea behind operator dispatchers is to provide an alternative syntax to operator overloading, similar to the original, but which allows to specify context information. 101 | 102 | The first argument (Which only is used to carry semantic/overloading info) specifies the operator signature. In the example, `operator==(float,float)` (Note the return type is ignored). 103 | The second argument specifies in what context the operator should be applied. By default contexts are specified by type tags, and the context resolution done though overload 104 | resolution. This approach has the advantage that the compiler is capable of inline all the Polyop machinery and only generate the code which really does the work (The body of 105 | the operator dispatcher action in this case). But exactly because that reason **operator dispatchers should be declared/defined on the same namespace of their context tags**, 106 | to allow the compiler to find the overload via ADL. 107 | 108 | ## Performance 109 | 110 | Polyop operators are designed to act as high-level syntactic sugar, with no runtime performance hits at all. All the Polyop machinery is erased at compile-time with minimal compiler optimizations (Common day to day inlining), generating only the code provided by the user. [Here](http://goo.gl/eF4zyp) is an example of a compilation with minimal optimization enabled (`-O1`) of this program: 111 | 112 | ``` cpp 113 | #include "operator_proxy.hpp" 114 | #include "operand.hpp" 115 | #include "operators.hpp" 116 | 117 | #include 118 | #include 119 | 120 | struct floating_point_context_tag{}; 121 | 122 | namespace pop 123 | { 124 | auto operator==( void(float,float) , pop::default_operator_tag ) 125 | { 126 | return []( float x , float y ) 127 | { 128 | std::cout << "Using default\n"; 129 | 130 | return x == y; 131 | }; 132 | } 133 | } 134 | 135 | auto operator==( void(float,float) , floating_point_context_tag ) 136 | { 137 | return []( float x , float y ) 138 | { 139 | std::cout << "Using floating-point\n"; 140 | 141 | return std::abs( x - y ) < 0.00001f; 142 | }; 143 | } 144 | 145 | 146 | int main() 147 | { 148 | using pop::trigger::_; 149 | 150 | auto op = _( 1.0f ) == 1.0f; 151 | 152 | std::cout << std::boolalpha << op() << std::endl; 153 | std::cout << std::boolalpha << op( floating_point_context_tag{} ) << std::endl; 154 | std::cout << std::boolalpha << (_(1.0f) == 2.0f)( floating_point_context_tag{} ) << std::endl; 155 | } 156 | 157 | ``` 158 | 159 | There is not output code for `pop::operand`, `pop::operator_proxy`, nor reference wrappers. The only code generated was the two Polyop operator dispatchers specified in the example, but with their body empty. Erasing something that depends on a function pointer is very hard for the compiler, since the pointer erases a lot of useful compile-time info. On the other hand, note how it successfully identified what the dispatcher does and its body was completely inlined: 160 | 161 | ``` asm 162 | pop::operator==(void (*)(float, float), pop::default_operator_tag): 163 | movl $0, %eax 164 | ret 165 | operator==(void (*)(float, float), floating_point_context_tag): 166 | movl $0, %eax 167 | ret 168 | ``` 169 | -------------------------------------------------------------------------------- /build/Debug/LLVM/Clang-Linux-x86/main.o.d: -------------------------------------------------------------------------------- 1 | build/Debug/LLVM/Clang-Linux-x86/main.o: main.cpp operator_proxy.hpp \ 2 | operand.hpp Turbo/type_traits.hpp Turbo/function.hpp \ 3 | Turbo/basic_types.hpp Turbo/algebra.hpp Turbo/function_alias_decl.hpp \ 4 | Turbo/chameleon.hpp Turbo/to_string.hpp Turbo/impl/demangle.hpp \ 5 | Turbo/to_runtime.hpp Turbo/fixed_point.hpp Turbo/utility.hpp \ 6 | Turbo/algorithm.hpp Turbo/high_order_functions.hpp Turbo/list.hpp \ 7 | Turbo/iterator.hpp Turbo/eval.hpp Turbo/enable_if.hpp \ 8 | Turbo/control_structures.hpp Turbo/lazy.hpp Turbo/lambda.hpp \ 9 | Turbo/let_expressions.hpp Turbo/warning.hpp \ 10 | Turbo/impl/CPP_META_MACROS.hpp Turbo/unconditional_false.hpp \ 11 | Turbo/utils/assert.hpp Turbo/list_algorithms.hpp \ 12 | Turbo/placeholders.hpp Turbo/integral_lists.hpp \ 13 | Turbo/integral_iterators.hpp Turbo/runtime_placeholders.hpp \ 14 | Turbo/runtime_chameleon.hpp operators.hpp functors.hpp 15 | 16 | operator_proxy.hpp: 17 | 18 | operand.hpp: 19 | 20 | Turbo/type_traits.hpp: 21 | 22 | Turbo/function.hpp: 23 | 24 | Turbo/basic_types.hpp: 25 | 26 | Turbo/algebra.hpp: 27 | 28 | Turbo/function_alias_decl.hpp: 29 | 30 | Turbo/chameleon.hpp: 31 | 32 | Turbo/to_string.hpp: 33 | 34 | Turbo/impl/demangle.hpp: 35 | 36 | Turbo/to_runtime.hpp: 37 | 38 | Turbo/fixed_point.hpp: 39 | 40 | Turbo/utility.hpp: 41 | 42 | Turbo/algorithm.hpp: 43 | 44 | Turbo/high_order_functions.hpp: 45 | 46 | Turbo/list.hpp: 47 | 48 | Turbo/iterator.hpp: 49 | 50 | Turbo/eval.hpp: 51 | 52 | Turbo/enable_if.hpp: 53 | 54 | Turbo/control_structures.hpp: 55 | 56 | Turbo/lazy.hpp: 57 | 58 | Turbo/lambda.hpp: 59 | 60 | Turbo/let_expressions.hpp: 61 | 62 | Turbo/warning.hpp: 63 | 64 | Turbo/impl/CPP_META_MACROS.hpp: 65 | 66 | Turbo/unconditional_false.hpp: 67 | 68 | Turbo/utils/assert.hpp: 69 | 70 | Turbo/list_algorithms.hpp: 71 | 72 | Turbo/placeholders.hpp: 73 | 74 | Turbo/integral_lists.hpp: 75 | 76 | Turbo/integral_iterators.hpp: 77 | 78 | Turbo/runtime_placeholders.hpp: 79 | 80 | Turbo/runtime_chameleon.hpp: 81 | 82 | operators.hpp: 83 | 84 | functors.hpp: 85 | -------------------------------------------------------------------------------- /build/Release/LLVM/Clang-Linux-x86/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Manu343726/Polyop/3876c1b503e933591b9baa1cda64cc2741ed50a2/build/Release/LLVM/Clang-Linux-x86/main.o -------------------------------------------------------------------------------- /build/Release/LLVM/Clang-Linux-x86/main.o.d: -------------------------------------------------------------------------------- 1 | build/Release/LLVM/Clang-Linux-x86/main.o: main.cpp operator_proxy.hpp \ 2 | operand.hpp Turbo/type_traits.hpp Turbo/function.hpp \ 3 | Turbo/basic_types.hpp Turbo/algebra.hpp Turbo/function_alias_decl.hpp \ 4 | Turbo/chameleon.hpp Turbo/to_string.hpp Turbo/impl/demangle.hpp \ 5 | Turbo/to_runtime.hpp Turbo/fixed_point.hpp Turbo/utility.hpp \ 6 | Turbo/algorithm.hpp Turbo/high_order_functions.hpp Turbo/list.hpp \ 7 | Turbo/iterator.hpp Turbo/eval.hpp Turbo/enable_if.hpp \ 8 | Turbo/control_structures.hpp Turbo/lazy.hpp Turbo/lambda.hpp \ 9 | Turbo/let_expressions.hpp Turbo/warning.hpp \ 10 | Turbo/impl/CPP_META_MACROS.hpp Turbo/unconditional_false.hpp \ 11 | Turbo/utils/assert.hpp Turbo/list_algorithms.hpp \ 12 | Turbo/placeholders.hpp Turbo/integral_lists.hpp \ 13 | Turbo/integral_iterators.hpp Turbo/runtime_placeholders.hpp \ 14 | Turbo/runtime_chameleon.hpp operators.hpp functors.hpp 15 | 16 | operator_proxy.hpp: 17 | 18 | operand.hpp: 19 | 20 | Turbo/type_traits.hpp: 21 | 22 | Turbo/function.hpp: 23 | 24 | Turbo/basic_types.hpp: 25 | 26 | Turbo/algebra.hpp: 27 | 28 | Turbo/function_alias_decl.hpp: 29 | 30 | Turbo/chameleon.hpp: 31 | 32 | Turbo/to_string.hpp: 33 | 34 | Turbo/impl/demangle.hpp: 35 | 36 | Turbo/to_runtime.hpp: 37 | 38 | Turbo/fixed_point.hpp: 39 | 40 | Turbo/utility.hpp: 41 | 42 | Turbo/algorithm.hpp: 43 | 44 | Turbo/high_order_functions.hpp: 45 | 46 | Turbo/list.hpp: 47 | 48 | Turbo/iterator.hpp: 49 | 50 | Turbo/eval.hpp: 51 | 52 | Turbo/enable_if.hpp: 53 | 54 | Turbo/control_structures.hpp: 55 | 56 | Turbo/lazy.hpp: 57 | 58 | Turbo/lambda.hpp: 59 | 60 | Turbo/let_expressions.hpp: 61 | 62 | Turbo/warning.hpp: 63 | 64 | Turbo/impl/CPP_META_MACROS.hpp: 65 | 66 | Turbo/unconditional_false.hpp: 67 | 68 | Turbo/utils/assert.hpp: 69 | 70 | Turbo/list_algorithms.hpp: 71 | 72 | Turbo/placeholders.hpp: 73 | 74 | Turbo/integral_lists.hpp: 75 | 76 | Turbo/integral_iterators.hpp: 77 | 78 | Turbo/runtime_placeholders.hpp: 79 | 80 | Turbo/runtime_chameleon.hpp: 81 | 82 | operators.hpp: 83 | 84 | functors.hpp: 85 | -------------------------------------------------------------------------------- /functors.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * File: functors.hpp 3 | * Author: manu343726 4 | * 5 | * Created on 10 de julio de 2014, 17:31 6 | */ 7 | 8 | #ifndef FUNCTORS_HPP 9 | #define FUNCTORS_HPP 10 | 11 | namespace pop 12 | { 13 | namespace operators 14 | { 15 | #define REMOVE_PARENS(...) __VA_ARGS__ 16 | 17 | #define BINARY_OPERATOR_FTOR( op , name ) template \ 18 | struct name; \ 19 | \ 20 | template \ 21 | struct name \ 22 | { \ 23 | name( const name&) = default; \ 24 | \ 25 | template \ 26 | auto operator()( CONTEXT rhs ) const \ 27 | { \ 28 | return [](ARGS...){} REMOVE_PARENS op rhs; \ 29 | } \ 30 | }; 31 | 32 | BINARY_OPERATOR_FTOR((==),equal); 33 | BINARY_OPERATOR_FTOR((!=),not_equal); 34 | BINARY_OPERATOR_FTOR((>) ,bigger_than); 35 | BINARY_OPERATOR_FTOR((<) ,less_than); 36 | BINARY_OPERATOR_FTOR((>=),bigger_or_equal); 37 | BINARY_OPERATOR_FTOR((<=),less_or_equal); 38 | 39 | BINARY_OPERATOR_FTOR((+),add); 40 | BINARY_OPERATOR_FTOR((-),sub); 41 | BINARY_OPERATOR_FTOR((*),mul); 42 | BINARY_OPERATOR_FTOR((/),div); 43 | 44 | BINARY_OPERATOR_FTOR((&&),logical_and); 45 | BINARY_OPERATOR_FTOR((||),logical_or); 46 | 47 | BINARY_OPERATOR_FTOR((&),bitwise_and); 48 | BINARY_OPERATOR_FTOR((|),bitwise_or); 49 | BINARY_OPERATOR_FTOR((^),bitwise_xor); 50 | BINARY_OPERATOR_FTOR((<<),leftshift); 51 | BINARY_OPERATOR_FTOR((>>),rightshift); 52 | 53 | BINARY_OPERATOR_FTOR((,),comma); 54 | 55 | } 56 | } 57 | 58 | #endif /* FUNCTORS_HPP */ 59 | 60 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * File: main.cpp 3 | * Author: manu343726 4 | * 5 | * Created on 10 de julio de 2014, 15:57 6 | */ 7 | 8 | #include "operator_proxy.hpp" 9 | #include "operand.hpp" 10 | #include "operators.hpp" 11 | 12 | #include 13 | #include 14 | 15 | 16 | 17 | 18 | struct floating_point_context_tag{}; 19 | 20 | namespace pop 21 | { 22 | auto operator==( void(float,float) , pop::default_operator_tag ) 23 | { 24 | return []( float x , float y ) 25 | { 26 | std::cout << "Using default\n"; 27 | 28 | return x == y; 29 | }; 30 | } 31 | } 32 | 33 | auto operator==( void(float,float) , floating_point_context_tag ) 34 | { 35 | return []( float x , float y ) 36 | { 37 | std::cout << "Using floating-point\n"; 38 | 39 | return std::abs( x - y ) < 0.00001f; 40 | }; 41 | } 42 | 43 | 44 | int main() 45 | { 46 | using pop::trigger::_; 47 | 48 | auto op = _( 1.0f ) == 1.0f; 49 | 50 | std::cout << std::boolalpha << op() << std::endl; 51 | std::cout << std::boolalpha << op( floating_point_context_tag{} ) << std::endl; 52 | std::cout << std::boolalpha << (_(1.0f) == 2.0f)( floating_point_context_tag{} ) << std::endl; 53 | } 54 | 55 | -------------------------------------------------------------------------------- /nbproject/Makefile-Debug.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Generated Makefile - do not edit! 3 | # 4 | # Edit the Makefile in the project folder instead (../Makefile). Each target 5 | # has a -pre and a -post target defined where you can add customized code. 6 | # 7 | # This makefile implements configuration specific macros and targets. 8 | 9 | 10 | # Environment 11 | MKDIR=mkdir 12 | CP=cp 13 | GREP=grep 14 | NM=nm 15 | CCADMIN=CCadmin 16 | RANLIB=ranlib 17 | CC=clang 18 | CCC=clang++ 19 | CXX=clang++ 20 | FC=gfortran 21 | AS=as 22 | 23 | # Macros 24 | CND_PLATFORM=LLVM/Clang-Linux-x86 25 | CND_DLIB_EXT=so 26 | CND_CONF=Debug 27 | CND_DISTDIR=dist 28 | CND_BUILDDIR=build 29 | 30 | # Include project Makefile 31 | include Makefile 32 | 33 | # Object Directory 34 | OBJECTDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM} 35 | 36 | # Object Files 37 | OBJECTFILES= \ 38 | ${OBJECTDIR}/main.o 39 | 40 | 41 | # C Compiler Flags 42 | CFLAGS= 43 | 44 | # CC Compiler Flags 45 | CCFLAGS=-std=c++1y 46 | CXXFLAGS=-std=c++1y 47 | 48 | # Fortran Compiler Flags 49 | FFLAGS= 50 | 51 | # Assembler Flags 52 | ASFLAGS= 53 | 54 | # Link Libraries and Options 55 | LDLIBSOPTIONS= 56 | 57 | # Build Targets 58 | .build-conf: ${BUILD_SUBPROJECTS} 59 | "${MAKE}" -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/polyop 60 | 61 | ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/polyop: ${OBJECTFILES} 62 | ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM} 63 | ${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/polyop ${OBJECTFILES} ${LDLIBSOPTIONS} 64 | 65 | ${OBJECTDIR}/main.o: main.cpp 66 | ${MKDIR} -p ${OBJECTDIR} 67 | ${RM} "$@.d" 68 | $(COMPILE.cc) -g -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/main.o main.cpp 69 | 70 | # Subprojects 71 | .build-subprojects: 72 | 73 | # Clean Targets 74 | .clean-conf: ${CLEAN_SUBPROJECTS} 75 | ${RM} -r ${CND_BUILDDIR}/${CND_CONF} 76 | ${RM} ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/polyop 77 | 78 | # Subprojects 79 | .clean-subprojects: 80 | 81 | # Enable dependency checking 82 | .dep.inc: .depcheck-impl 83 | 84 | include .dep.inc 85 | -------------------------------------------------------------------------------- /nbproject/Makefile-Release.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Generated Makefile - do not edit! 3 | # 4 | # Edit the Makefile in the project folder instead (../Makefile). Each target 5 | # has a -pre and a -post target defined where you can add customized code. 6 | # 7 | # This makefile implements configuration specific macros and targets. 8 | 9 | 10 | # Environment 11 | MKDIR=mkdir 12 | CP=cp 13 | GREP=grep 14 | NM=nm 15 | CCADMIN=CCadmin 16 | RANLIB=ranlib 17 | CC=clang 18 | CCC=clang++ 19 | CXX=clang++ 20 | FC=gfortran 21 | AS=as 22 | 23 | # Macros 24 | CND_PLATFORM=LLVM/Clang-Linux-x86 25 | CND_DLIB_EXT=so 26 | CND_CONF=Release 27 | CND_DISTDIR=dist 28 | CND_BUILDDIR=build 29 | 30 | # Include project Makefile 31 | include Makefile 32 | 33 | # Object Directory 34 | OBJECTDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM} 35 | 36 | # Object Files 37 | OBJECTFILES= \ 38 | ${OBJECTDIR}/main.o 39 | 40 | 41 | # C Compiler Flags 42 | CFLAGS= 43 | 44 | # CC Compiler Flags 45 | CCFLAGS=-std=c++1y 46 | CXXFLAGS=-std=c++1y 47 | 48 | # Fortran Compiler Flags 49 | FFLAGS= 50 | 51 | # Assembler Flags 52 | ASFLAGS= 53 | 54 | # Link Libraries and Options 55 | LDLIBSOPTIONS= 56 | 57 | # Build Targets 58 | .build-conf: ${BUILD_SUBPROJECTS} 59 | "${MAKE}" -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/polyop 60 | 61 | ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/polyop: ${OBJECTFILES} 62 | ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM} 63 | ${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/polyop ${OBJECTFILES} ${LDLIBSOPTIONS} 64 | 65 | ${OBJECTDIR}/main.o: main.cpp 66 | ${MKDIR} -p ${OBJECTDIR} 67 | ${RM} "$@.d" 68 | $(COMPILE.cc) -O2 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/main.o main.cpp 69 | 70 | # Subprojects 71 | .build-subprojects: 72 | 73 | # Clean Targets 74 | .clean-conf: ${CLEAN_SUBPROJECTS} 75 | ${RM} -r ${CND_BUILDDIR}/${CND_CONF} 76 | ${RM} ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/polyop 77 | 78 | # Subprojects 79 | .clean-subprojects: 80 | 81 | # Enable dependency checking 82 | .dep.inc: .depcheck-impl 83 | 84 | include .dep.inc 85 | -------------------------------------------------------------------------------- /nbproject/Makefile-impl.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Generated Makefile - do not edit! 3 | # 4 | # Edit the Makefile in the project folder instead (../Makefile). Each target 5 | # has a pre- and a post- target defined where you can add customization code. 6 | # 7 | # This makefile implements macros and targets common to all configurations. 8 | # 9 | # NOCDDL 10 | 11 | 12 | # Building and Cleaning subprojects are done by default, but can be controlled with the SUB 13 | # macro. If SUB=no, subprojects will not be built or cleaned. The following macro 14 | # statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf 15 | # and .clean-reqprojects-conf unless SUB has the value 'no' 16 | SUB_no=NO 17 | SUBPROJECTS=${SUB_${SUB}} 18 | BUILD_SUBPROJECTS_=.build-subprojects 19 | BUILD_SUBPROJECTS_NO= 20 | BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}} 21 | CLEAN_SUBPROJECTS_=.clean-subprojects 22 | CLEAN_SUBPROJECTS_NO= 23 | CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}} 24 | 25 | 26 | # Project Name 27 | PROJECTNAME=Polyop 28 | 29 | # Active Configuration 30 | DEFAULTCONF=Debug 31 | CONF=${DEFAULTCONF} 32 | 33 | # All Configurations 34 | ALLCONFS=Debug Release 35 | 36 | 37 | # build 38 | .build-impl: .build-pre .validate-impl .depcheck-impl 39 | @#echo "=> Running $@... Configuration=$(CONF)" 40 | "${MAKE}" -f nbproject/Makefile-${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .build-conf 41 | 42 | 43 | # clean 44 | .clean-impl: .clean-pre .validate-impl .depcheck-impl 45 | @#echo "=> Running $@... Configuration=$(CONF)" 46 | "${MAKE}" -f nbproject/Makefile-${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .clean-conf 47 | 48 | 49 | # clobber 50 | .clobber-impl: .clobber-pre .depcheck-impl 51 | @#echo "=> Running $@..." 52 | for CONF in ${ALLCONFS}; \ 53 | do \ 54 | "${MAKE}" -f nbproject/Makefile-$${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .clean-conf; \ 55 | done 56 | 57 | # all 58 | .all-impl: .all-pre .depcheck-impl 59 | @#echo "=> Running $@..." 60 | for CONF in ${ALLCONFS}; \ 61 | do \ 62 | "${MAKE}" -f nbproject/Makefile-$${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .build-conf; \ 63 | done 64 | 65 | # build tests 66 | .build-tests-impl: .build-impl .build-tests-pre 67 | @#echo "=> Running $@... Configuration=$(CONF)" 68 | "${MAKE}" -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-tests-conf 69 | 70 | # run tests 71 | .test-impl: .build-tests-impl .test-pre 72 | @#echo "=> Running $@... Configuration=$(CONF)" 73 | "${MAKE}" -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .test-conf 74 | 75 | # dependency checking support 76 | .depcheck-impl: 77 | @echo "# This code depends on make tool being used" >.dep.inc 78 | @if [ -n "${MAKE_VERSION}" ]; then \ 79 | echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \ 80 | echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \ 81 | echo "include \$${DEPFILES}" >>.dep.inc; \ 82 | echo "endif" >>.dep.inc; \ 83 | else \ 84 | echo ".KEEP_STATE:" >>.dep.inc; \ 85 | echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \ 86 | fi 87 | 88 | # configuration validation 89 | .validate-impl: 90 | @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \ 91 | then \ 92 | echo ""; \ 93 | echo "Error: can not find the makefile for configuration '${CONF}' in project ${PROJECTNAME}"; \ 94 | echo "See 'make help' for details."; \ 95 | echo "Current directory: " `pwd`; \ 96 | echo ""; \ 97 | fi 98 | @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \ 99 | then \ 100 | exit 1; \ 101 | fi 102 | 103 | 104 | # help 105 | .help-impl: .help-pre 106 | @echo "This makefile supports the following configurations:" 107 | @echo " ${ALLCONFS}" 108 | @echo "" 109 | @echo "and the following targets:" 110 | @echo " build (default target)" 111 | @echo " clean" 112 | @echo " clobber" 113 | @echo " all" 114 | @echo " help" 115 | @echo "" 116 | @echo "Makefile Usage:" 117 | @echo " make [CONF=] [SUB=no] build" 118 | @echo " make [CONF=] [SUB=no] clean" 119 | @echo " make [SUB=no] clobber" 120 | @echo " make [SUB=no] all" 121 | @echo " make help" 122 | @echo "" 123 | @echo "Target 'build' will build a specific configuration and, unless 'SUB=no'," 124 | @echo " also build subprojects." 125 | @echo "Target 'clean' will clean a specific configuration and, unless 'SUB=no'," 126 | @echo " also clean subprojects." 127 | @echo "Target 'clobber' will remove all built files from all configurations and," 128 | @echo " unless 'SUB=no', also from subprojects." 129 | @echo "Target 'all' will will build all configurations and, unless 'SUB=no'," 130 | @echo " also build subprojects." 131 | @echo "Target 'help' prints this message." 132 | @echo "" 133 | 134 | -------------------------------------------------------------------------------- /nbproject/Makefile-variables.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Generated - do not edit! 3 | # 4 | # NOCDDL 5 | # 6 | CND_BASEDIR=`pwd` 7 | CND_BUILDDIR=build 8 | CND_DISTDIR=dist 9 | # Debug configuration 10 | CND_PLATFORM_Debug=LLVM/Clang-Linux-x86 11 | CND_ARTIFACT_DIR_Debug=dist/Debug/LLVM/Clang-Linux-x86 12 | CND_ARTIFACT_NAME_Debug=polyop 13 | CND_ARTIFACT_PATH_Debug=dist/Debug/LLVM/Clang-Linux-x86/polyop 14 | CND_PACKAGE_DIR_Debug=dist/Debug/LLVM/Clang-Linux-x86/package 15 | CND_PACKAGE_NAME_Debug=polyop.tar 16 | CND_PACKAGE_PATH_Debug=dist/Debug/LLVM/Clang-Linux-x86/package/polyop.tar 17 | # Release configuration 18 | CND_PLATFORM_Release=LLVM/Clang-Linux-x86 19 | CND_ARTIFACT_DIR_Release=dist/Release/LLVM/Clang-Linux-x86 20 | CND_ARTIFACT_NAME_Release=polyop 21 | CND_ARTIFACT_PATH_Release=dist/Release/LLVM/Clang-Linux-x86/polyop 22 | CND_PACKAGE_DIR_Release=dist/Release/LLVM/Clang-Linux-x86/package 23 | CND_PACKAGE_NAME_Release=polyop.tar 24 | CND_PACKAGE_PATH_Release=dist/Release/LLVM/Clang-Linux-x86/package/polyop.tar 25 | # 26 | # include compiler specific variables 27 | # 28 | # dmake command 29 | ROOT:sh = test -f nbproject/private/Makefile-variables.mk || \ 30 | (mkdir -p nbproject/private && touch nbproject/private/Makefile-variables.mk) 31 | # 32 | # gmake command 33 | .PHONY: $(shell test -f nbproject/private/Makefile-variables.mk || (mkdir -p nbproject/private && touch nbproject/private/Makefile-variables.mk)) 34 | # 35 | include nbproject/private/Makefile-variables.mk 36 | -------------------------------------------------------------------------------- /nbproject/Package-Debug.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | # 4 | # Generated - do not edit! 5 | # 6 | 7 | # Macros 8 | TOP=`pwd` 9 | CND_PLATFORM=LLVM/Clang-Linux-x86 10 | CND_CONF=Debug 11 | CND_DISTDIR=dist 12 | CND_BUILDDIR=build 13 | CND_DLIB_EXT=so 14 | NBTMPDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tmp-packaging 15 | TMPDIRNAME=tmp-packaging 16 | OUTPUT_PATH=${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/polyop 17 | OUTPUT_BASENAME=polyop 18 | PACKAGE_TOP_DIR=polyop/ 19 | 20 | # Functions 21 | function checkReturnCode 22 | { 23 | rc=$? 24 | if [ $rc != 0 ] 25 | then 26 | exit $rc 27 | fi 28 | } 29 | function makeDirectory 30 | # $1 directory path 31 | # $2 permission (optional) 32 | { 33 | mkdir -p "$1" 34 | checkReturnCode 35 | if [ "$2" != "" ] 36 | then 37 | chmod $2 "$1" 38 | checkReturnCode 39 | fi 40 | } 41 | function copyFileToTmpDir 42 | # $1 from-file path 43 | # $2 to-file path 44 | # $3 permission 45 | { 46 | cp "$1" "$2" 47 | checkReturnCode 48 | if [ "$3" != "" ] 49 | then 50 | chmod $3 "$2" 51 | checkReturnCode 52 | fi 53 | } 54 | 55 | # Setup 56 | cd "${TOP}" 57 | mkdir -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package 58 | rm -rf ${NBTMPDIR} 59 | mkdir -p ${NBTMPDIR} 60 | 61 | # Copy files and create directories and links 62 | cd "${TOP}" 63 | makeDirectory "${NBTMPDIR}/polyop/bin" 64 | copyFileToTmpDir "${OUTPUT_PATH}" "${NBTMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755 65 | 66 | 67 | # Generate tar file 68 | cd "${TOP}" 69 | rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/polyop.tar 70 | cd ${NBTMPDIR} 71 | tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/polyop.tar * 72 | checkReturnCode 73 | 74 | # Cleanup 75 | cd "${TOP}" 76 | rm -rf ${NBTMPDIR} 77 | -------------------------------------------------------------------------------- /nbproject/Package-Release.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | # 4 | # Generated - do not edit! 5 | # 6 | 7 | # Macros 8 | TOP=`pwd` 9 | CND_PLATFORM=LLVM/Clang-Linux-x86 10 | CND_CONF=Release 11 | CND_DISTDIR=dist 12 | CND_BUILDDIR=build 13 | CND_DLIB_EXT=so 14 | NBTMPDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tmp-packaging 15 | TMPDIRNAME=tmp-packaging 16 | OUTPUT_PATH=${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/polyop 17 | OUTPUT_BASENAME=polyop 18 | PACKAGE_TOP_DIR=polyop/ 19 | 20 | # Functions 21 | function checkReturnCode 22 | { 23 | rc=$? 24 | if [ $rc != 0 ] 25 | then 26 | exit $rc 27 | fi 28 | } 29 | function makeDirectory 30 | # $1 directory path 31 | # $2 permission (optional) 32 | { 33 | mkdir -p "$1" 34 | checkReturnCode 35 | if [ "$2" != "" ] 36 | then 37 | chmod $2 "$1" 38 | checkReturnCode 39 | fi 40 | } 41 | function copyFileToTmpDir 42 | # $1 from-file path 43 | # $2 to-file path 44 | # $3 permission 45 | { 46 | cp "$1" "$2" 47 | checkReturnCode 48 | if [ "$3" != "" ] 49 | then 50 | chmod $3 "$2" 51 | checkReturnCode 52 | fi 53 | } 54 | 55 | # Setup 56 | cd "${TOP}" 57 | mkdir -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package 58 | rm -rf ${NBTMPDIR} 59 | mkdir -p ${NBTMPDIR} 60 | 61 | # Copy files and create directories and links 62 | cd "${TOP}" 63 | makeDirectory "${NBTMPDIR}/polyop/bin" 64 | copyFileToTmpDir "${OUTPUT_PATH}" "${NBTMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755 65 | 66 | 67 | # Generate tar file 68 | cd "${TOP}" 69 | rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/polyop.tar 70 | cd ${NBTMPDIR} 71 | tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/polyop.tar * 72 | checkReturnCode 73 | 74 | # Cleanup 75 | cd "${TOP}" 76 | rm -rf ${NBTMPDIR} 77 | -------------------------------------------------------------------------------- /nbproject/configurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | functors.hpp 8 | operand.hpp 9 | operator_proxy.hpp 10 | operators.hpp 11 | 12 | 15 | 16 | 19 | main.cpp 20 | 21 | 25 | 26 | 30 | Makefile 31 | 32 | 33 | Makefile 34 | 35 | 36 | 37 | default 38 | true 39 | false 40 | 41 | 42 | 43 | -std=c++1y 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | default 60 | true 61 | false 62 | 63 | 64 | 65 | 5 66 | 67 | 68 | 5 69 | -std=c++1y 70 | 71 | 72 | 5 73 | 74 | 75 | 5 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /nbproject/private/Makefile-variables.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Generated - do not edit! 3 | # 4 | # NOCDDL 5 | # 6 | # Debug configuration 7 | # Release configuration 8 | -------------------------------------------------------------------------------- /nbproject/private/configurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Makefile 4 | 5 | 6 | 7 | localhost 8 | 2 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | gdb 24 | 25 | 26 | 27 | "${OUTPUT_PATH}" 28 | 29 | "${OUTPUT_PATH}" 30 | 31 | true 32 | 0 33 | 0 34 | 35 | 36 | 37 | 38 | 39 | 40 | localhost 41 | 2 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | gdb 57 | 58 | 59 | 60 | "${OUTPUT_PATH}" 61 | 62 | "${OUTPUT_PATH}" 63 | 64 | true 65 | 0 66 | 0 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /nbproject/private/launcher.properties: -------------------------------------------------------------------------------- 1 | # Launchers File syntax: 2 | # 3 | # [Must-have property line] 4 | # launcher1.runCommand= 5 | # [Optional extra properties] 6 | # launcher1.displayName= 7 | # launcher1.buildCommand= 8 | # launcher1.runDir= 9 | # launcher1.symbolFiles= 10 | # launcher1.env.= 11 | # (If this value is quoted with ` it is handled as a native command which execution result will become the value) 12 | # [Common launcher properties] 13 | # common.runDir= 14 | # (This value is overwritten by a launcher specific runDir value if the latter exists) 15 | # common.env.= 16 | # (Environment variables from common launcher are merged with launcher specific variables) 17 | # common.symbolFiles= 18 | # (This value is overwritten by a launcher specific symbolFiles value if the latter exists) 19 | # 20 | # In runDir, symbolFiles and env fields you can use these macroses: 21 | # ${PROJECT_DIR} - project directory absolute path 22 | # ${OUTPUT_PATH} - linker output path (relative to project directory path) 23 | # ${OUTPUT_BASENAME}- linker output filename 24 | # ${TESTDIR} - test files directory (relative to project directory path) 25 | # ${OBJECTDIR} - object files directory (relative to project directory path) 26 | # ${CND_DISTDIR} - distribution directory (relative to project directory path) 27 | # ${CND_BUILDDIR} - build directory (relative to project directory path) 28 | # ${CND_PLATFORM} - platform name 29 | # ${CND_CONF} - configuration name 30 | # ${CND_DLIB_EXT} - dynamic library extension 31 | # 32 | # All the project launchers must be listed in the file! 33 | # 34 | # launcher1.runCommand=... 35 | # launcher2.runCommand=... 36 | # ... 37 | # common.runDir=... 38 | # common.env.KEY=VALUE 39 | 40 | # launcher1.runCommand= -------------------------------------------------------------------------------- /nbproject/private/private.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1 5 | 1 6 | 7 | 8 | 9 | 10 | file:/home/manu343726/Dropbox/PROYECTOS/C_C++/Polyop/functors.hpp 11 | file:/home/manu343726/Dropbox/PROYECTOS/C_C++/Polyop/operators.hpp 12 | file:/home/manu343726/Dropbox/PROYECTOS/C_C++/Polyop/main.cpp 13 | file:/home/manu343726/Dropbox/PROYECTOS/C_C++/Polyop/operand.hpp 14 | file:/home/manu343726/Dropbox/PROYECTOS/C_C++/Polyop/operator_proxy.hpp 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.cnd.makeproject 4 | 5 | 6 | Polyop 7 | 8 | cpp 9 | hpp 10 | UTF-8 11 | 12 | 13 | 14 | 15 | Debug 16 | 1 17 | 18 | 19 | Release 20 | 1 21 | 22 | 23 | 24 | false 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /operand.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * File: operand.hpp 3 | * Author: manu343726 4 | * 5 | * Created on 10 de julio de 2014, 15:58 6 | */ 7 | 8 | #ifndef OPERAND_HPP 9 | #define OPERAND_HPP 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace pop 16 | { 17 | namespace impl 18 | { 19 | template 20 | struct operand 21 | { 22 | public: 23 | operand( const T& r ) : 24 | _op_ref{ r } 25 | {} 26 | 27 | operand( const operand& ) = default; 28 | 29 | const T& get() const 30 | { 31 | return _op_ref.get(); 32 | } 33 | 34 | explicit operator T&() const 35 | { 36 | return get(); 37 | } 38 | private: 39 | std::reference_wrapper _op_ref; 40 | }; 41 | 42 | template 43 | struct operand 44 | { 45 | public: 46 | operand( T&& op ) : _op{ std::move( op ) } 47 | {} 48 | 49 | T& get() 50 | { 51 | return _op; 52 | } 53 | 54 | const T& get() const 55 | { 56 | return _op; 57 | } 58 | 59 | explicit operator const T&() const 60 | { 61 | return get(); 62 | } 63 | 64 | explicit operator T() const 65 | { 66 | return get(); 67 | } 68 | private: 69 | T _op; 70 | }; 71 | } 72 | 73 | template 74 | using operand = pop::impl::operand::type, 75 | std::is_lvalue_reference>; 76 | 77 | template 78 | pop::operand wrap( T&& op ) 79 | { 80 | return { std::forward( op ) }; 81 | } 82 | 83 | template 84 | pop::operand make_op( ARGS&&... args ) 85 | { 86 | return { args... }; 87 | } 88 | 89 | namespace trigger 90 | { 91 | template 92 | pop::operand _( T&& op ) 93 | { 94 | return pop::wrap( std::forward( op ) ); 95 | } 96 | } 97 | } 98 | 99 | #endif /* OPERAND_HPP */ 100 | 101 | -------------------------------------------------------------------------------- /operator_proxy.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * File: operator_proxy.hpp 3 | * Author: manu343726 4 | * 5 | * Created on 10 de julio de 2014, 16:53 6 | */ 7 | 8 | #ifndef OPERATOR_PROXY_HPP 9 | #define OPERATOR_PROXY_HPP 10 | 11 | #include "operand.hpp" 12 | 13 | #include 14 | #include 15 | 16 | namespace pop 17 | { 18 | struct default_operator_tag{}; 19 | extern const default_operator_tag default_operator; 20 | 21 | template 22 | struct operator_proxy 23 | { 24 | template 25 | operator_proxy( OP_DISPATCH&& op , LHS_&& lhs , RHS_&& rhs ) : 26 | _operator_dispatcher( op ), 27 | _lhs{ lhs }, 28 | _rhs{ rhs } 29 | {} 30 | 31 | template 32 | auto operator()( CONTEXT_TAG tag ) const 33 | { 34 | auto op = _operator_dispatcher( tag ); 35 | 36 | return op( _lhs.get() , _rhs.get() ); 37 | } 38 | 39 | auto operator()() const 40 | { 41 | return (*this)( pop::default_operator ); 42 | } 43 | 44 | template< typename CONTEXT_TAG> 45 | auto context( CONTEXT_TAG tag ) 46 | { 47 | return (*this)( tag ); 48 | } 49 | 50 | operator auto() 51 | { 52 | return (*this)(); 53 | } 54 | private: 55 | OP _operator_dispatcher; 56 | pop::operand _lhs; 57 | pop::operand _rhs; 58 | }; 59 | 60 | template 61 | pop::operator_proxy::type, 62 | typename std::decay::type, 63 | typename std::decay::type> 64 | make_proxy( OP&& operator_ , const pop::operand& lhs , const pop::operand& rhs ) 65 | { 66 | return { operator_ , lhs , rhs }; 67 | } 68 | 69 | template 70 | pop::operator_proxy::type, 71 | typename std::decay::type, 72 | RHS> 73 | make_proxy( OP&& operator_ , const pop::operand& lhs , const RHS& rhs ) 74 | { 75 | return { operator_ , lhs , rhs }; 76 | } 77 | 78 | template 79 | pop::operator_proxy::type, 80 | LHS, 81 | typename std::decay::type> 82 | make_proxy( OP&& operator_ , const LHS& lhs , const pop::operand& rhs ) 83 | { 84 | return { operator_ , lhs , rhs }; 85 | } 86 | } 87 | 88 | 89 | #endif /* OPERATOR_PROXY_HPP */ 90 | 91 | -------------------------------------------------------------------------------- /operators.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * File: operators.hpp 3 | * Author: manu343726 4 | * 5 | * Created on 10 de julio de 2014, 17:49 6 | */ 7 | 8 | #ifndef OPERATORS_HPP 9 | #define OPERATORS_HPP 10 | 11 | #include "functors.hpp" 12 | #include "operator_proxy.hpp" 13 | 14 | #include 15 | 16 | using namespace std::placeholders; 17 | 18 | #define REMOVE_PARENS(...) __VA_ARGS__ 19 | 20 | #define POLYOP_DEFAULT_OPERATORS( op , functor ) \ 21 | template 22 | 23 | 24 | #define BINARY_OP_WRAPPER( op , functor ) \ 25 | template \ 26 | auto operator REMOVE_PARENS op( const pop::operand& lhs , const pop::operand& rhs ) \ 27 | { \ 28 | return pop::make_proxy( pop::operators::functor{} , lhs , rhs ); \ 29 | } \ 30 | \ 31 | template \ 32 | auto operator REMOVE_PARENS op( const pop::operand& lhs , const RHS& rhs ) \ 33 | { \ 34 | return pop::make_proxy( pop::operators::functor{} , lhs , rhs ); \ 35 | } \ 36 | \ 37 | template \ 38 | auto operator REMOVE_PARENS op( const LHS& lhs , const pop::operand& rhs ) \ 39 | { \ 40 | return pop::make_proxy( pop::operators::functor{} , lhs , rhs ); \ 41 | } 42 | 43 | 44 | BINARY_OP_WRAPPER((==),equal); 45 | BINARY_OP_WRAPPER((!=),not_equal); 46 | BINARY_OP_WRAPPER((>) ,bigger_than); 47 | BINARY_OP_WRAPPER((<) ,less_than); 48 | BINARY_OP_WRAPPER((>=),bigger_or_equal); 49 | BINARY_OP_WRAPPER((<=),less_or_equal); 50 | 51 | BINARY_OP_WRAPPER((+),add); 52 | BINARY_OP_WRAPPER((-),sub); 53 | BINARY_OP_WRAPPER((*),mul); 54 | BINARY_OP_WRAPPER((/),div); 55 | 56 | BINARY_OP_WRAPPER((&&),logical_and); 57 | BINARY_OP_WRAPPER((||),logical_or); 58 | 59 | BINARY_OP_WRAPPER((&),bitwise_and); 60 | BINARY_OP_WRAPPER((|),bitwise_or); 61 | BINARY_OP_WRAPPER((^),bitwise_xor); 62 | BINARY_OP_WRAPPER((<<),leftshift); 63 | BINARY_OP_WRAPPER((>>),rightshift); 64 | 65 | BINARY_OP_WRAPPER((,),comma); 66 | 67 | 68 | #endif /* OPERATORS_HPP */ 69 | 70 | -------------------------------------------------------------------------------- /polyop.hpp: -------------------------------------------------------------------------------- 1 | #ifndef POLYOP_HPP 2 | #define POLYOP_HPP 3 | 4 | #include "operand.hpp" 5 | #include "functors.hpp" 6 | #include "operators.hpp" 7 | 8 | #endif /* POLYOP_HPP */ 9 | --------------------------------------------------------------------------------