summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpeterbell10 <peterbell10@live.co.uk>2018-07-24 23:30:05 +0200
committerTiger Wang <ziwei.tiger@outlook.com>2018-07-24 23:30:05 +0200
commitb5f29d5d2cfd2b17cda5543fec0bcbdd3fa5c372 (patch)
tree6884d220b67e116ac7dabbc4c2c3ff195f4a9c83
parentOptimise chunk set (#4260) (diff)
downloadcuberite-b5f29d5d2cfd2b17cda5543fec0bcbdd3fa5c372.tar
cuberite-b5f29d5d2cfd2b17cda5543fec0bcbdd3fa5c372.tar.gz
cuberite-b5f29d5d2cfd2b17cda5543fec0bcbdd3fa5c372.tar.bz2
cuberite-b5f29d5d2cfd2b17cda5543fec0bcbdd3fa5c372.tar.lz
cuberite-b5f29d5d2cfd2b17cda5543fec0bcbdd3fa5c372.tar.xz
cuberite-b5f29d5d2cfd2b17cda5543fec0bcbdd3fa5c372.tar.zst
cuberite-b5f29d5d2cfd2b17cda5543fec0bcbdd3fa5c372.zip
-rw-r--r--Doxyfile2
-rw-r--r--src/FunctionRef.h37
2 files changed, 32 insertions, 7 deletions
diff --git a/Doxyfile b/Doxyfile
index 90ad55ddb..e70103087 100644
--- a/Doxyfile
+++ b/Doxyfile
@@ -194,7 +194,7 @@ SEPARATE_MEMBER_PAGES = NO
# The TAB_SIZE tag can be used to set the number of spaces in a tab.
# Doxygen uses this value to replace tabs by spaces in code fragments.
-TAB_SIZE = 2
+TAB_SIZE = 4
# This tag can be used to specify a number of aliases that acts
# as commands in the documentation. An alias has the form "name=value".
diff --git a/src/FunctionRef.h b/src/FunctionRef.h
index 8215fd0db..753d540a7 100644
--- a/src/FunctionRef.h
+++ b/src/FunctionRef.h
@@ -6,17 +6,42 @@ template <class Signature>
class cFunctionRef;
/** A light-weight, type-erased reference to a function object.
-This is similar to a std::function but doesn't copy the function object
-which means that mutable function objects will be modified for the caller
-but would not be if using a std::function (See #3990 for implications of this).
-A cFunctionRef has no empty state but is non-owning and so is safe to call
-as long as the referred object is still alive. */
+
+### Usage
+
+`cFunctionRef` is used whenever you call a normal function with a lambda. e.g.
+one of the `cWorld::DoWith` functions,
+
+ m_World->DoWithChunkAt(BlockPos, [](cChunk & a_Chunk) -> bool
+ {
+ ...
+ }
+ );
+
+It looks like you're calling it with a lambda but that would require
+`DoWithChunkAt` to be a template. The function is really being called with
+`cFunctionRef<bool(cChunk&)>` which is constructed from the lambda via a
+templated constructor. This gives you a generic pointer to the lambda which
+doesn't depend on the type of the function object it references.
+
+### Notes
+
+- This is similar to a `std::function` but doesn't copy the function object.
+This means that mutable function objects will be modified for the caller but
+would not be if using a `std::function` (See #3990 for implications of this).
+
+- A `cFunctionRef` has no empty state but is non-owning and so is safe to call as
+long as the referred object is still alive. */
template <class Ret, class... Args>
class cFunctionRef<Ret(Args...)>
{
public:
/** Construct from a function object. */
- template <class FunctionObject>
+ template <class FunctionObject,
+ typename std::enable_if< // Don't disable the default copy constructor
+ !std::is_same<typename std::decay<FunctionObject>::type, cFunctionRef>::value,
+ int>::type = 0
+ >
cFunctionRef(FunctionObject && a_FunctionObject)
{
// Store an opaque reference to the object.