summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-10-19 13:12:47 +0200
committerSven Gothel <[email protected]>2020-10-19 13:12:47 +0200
commitc43b6689bd0d98cc18d7c0410af2546f529e0099 (patch)
treec7c307097408d53df7f67c4919a6270321d72b81
parent28b2cc4c7bd68b1e8507530070837c1c57dc7cf3 (diff)
function_def: Fix NullInvocationFunc template declaration and clone override; Also use shared_ptr<T>(T) ctor only once ;-)v0.2.2
-rw-r--r--include/jau/function_def.hpp24
1 files changed, 10 insertions, 14 deletions
diff --git a/include/jau/function_def.hpp b/include/jau/function_def.hpp
index 068324e..d5242af 100644
--- a/include/jau/function_def.hpp
+++ b/include/jau/function_def.hpp
@@ -101,14 +101,14 @@ namespace jau {
virtual std::string toString() const = 0;
};
- template<typename R, typename C, typename... A>
+ template<typename R, typename... A>
class NullInvocationFunc : public InvocationFunc<R, A...> {
public:
NullInvocationFunc() noexcept { }
int getType() const noexcept override { return 0; }
- InvocationFunc<R, A...> clone() const noexcept override { return NullInvocationFunc(); }
+ InvocationFunc<R, A...> * clone() const noexcept override { return new NullInvocationFunc(); }
R invoke(A...) override {
return (R)0;
@@ -315,24 +315,20 @@ namespace jau {
* Constructs an instance with a null function.
*/
FunctionDef() noexcept
- : func(std::shared_ptr<InvocationFunc<R, A...>>( new NullInvocationFunc<R, A...>() ))
- {};
-
- /**
- * Constructs an instance using the shared InvocationFunc<R, A...> function.
- */
- FunctionDef(std::shared_ptr<InvocationFunc<R, A...>> _func) noexcept
- : func(_func) { }
+ : func( new NullInvocationFunc<R, A...>() ) { }
/**
* Constructs an instance by wrapping the given naked InvocationFunc<R, A...> function pointer
* in a shared_ptr and taking ownership.
- * <p>
- * A convenience method.
- * </p.
*/
FunctionDef(InvocationFunc<R, A...> * _funcPtr) noexcept
- : func(std::shared_ptr<InvocationFunc<R, A...>>(_funcPtr)) { }
+ : func( _funcPtr ) { }
+
+ /**
+ * Constructs an instance using the shared InvocationFunc<R, A...> function.
+ */
+ explicit FunctionDef(std::shared_ptr<InvocationFunc<R, A...>> _func) noexcept
+ : func( _func ) { }
FunctionDef(const FunctionDef &o) noexcept = default;
FunctionDef(FunctionDef &&o) noexcept = default;