Mentions légales du service

Skip to content
Snippets Groups Projects

Typo found during operators dry run

4 unresolved threads

@vicente.mataix @steff

  • Add Coliru links when missing
  • Rework spaceship operator (to be discussed)
  • Add text about functor arguments
  • Some typos

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
138 138 "cell_type": "markdown",
139 139 "metadata": {},
140 140 "source": [
141 "C++ provides the way to mimic this behaviour with **operator overloading**. This is a very powerful conceit, but also one that should be approached with some care...\n",
  • 446 448 "cell_type": "markdown",
    447 449 "metadata": {},
    448 450 "source": [
    449 "[Examples](https://www.modernescpp.com/index.php/c-20-more-details-to-the-spaceship-operator) on [the](https://devblogs.microsoft.com/cppblog/simplify-your-code-with-rocket-science-c20s-spaceship-operator/) Web often show the defaulting of a comparison used directly upon the spaceship operator, which is something I will have to investigate when I upgrade to C++ 20 as it seems at first sight rather dangerous to me (see the `Rational` example, where even the default `operator==` is unlikely to be what we want)."
  • 191 191 "cell_type": "markdown",
    192 192 "metadata": {},
    193 193 "source": [
    194 "```txt\n",
    194 195 "** Error in `./prog.exe': double free or corruption (fasttop): 0x0000000001532da0 **\n",
    196 "```\n",
    195 197 "\n",
    196 "So what's the deal? The default operator copies all the data attributes from `v1` to `v2`... which here amounts only to the `array_` pointer. But it really copies that: the pointer, and not the data pointed by this pointer. So in fine v1 and v2 points to the same area of memory, and the issue is that we attempt to free the same memory twice.\n",
  • 23 23 "source": [
    24 24 "## What is a functor?\n",
    25 25 "\n",
    26 "We can provide a class with an operator `operator()` that allows to give its objects a function behavior. In other words: if you write an expression in which an object is used as if it were a function, it is its execution operator that is invoked. \n",
    26 "We can provide a class with an `operator()` that allows to give its objects a function behavior. In other words: if you write an expression in which an object is used as if it were a function, it is its execution operator that is invoked. \n",
    27 27 "\n",
    28 28 "We can also see these *functional objects*, or *functors*, as functions to which we would have added state parameters from one call to another.\n",
    29 29 "\n",
    30 "The return type is not constrained and might be defined as you wish in the class (`double` is used here):"
    30 "The return type and the arguments are not constrained and might be defined as you wish in the class (`int` is used here for return type, and an `int` is required as argument):"
  • Few (very minor) modifications here - one of each is a typo not related to your fixes:

    https://gitlab.inria.fr/sgilles/gettingstartedwithmoderncpp/-/tree/typo_found_during_operators_dry_run

    (I didn't push to your branch as I rebased first on master)

    Edited by GILLES Sebastien
  • Vicente Mataix Ferrándiz approved this merge request

    approved this merge request

  • Integrated after @vrouvrea approval.

  • Please register or sign in to reply
    Loading