[Dune] [Dune-Commit] dune-grid r7830 - trunk/dune/grid/uggrid

Jö Fahlke jorrit at jorrit.de
Wed Jan 11 13:10:06 CET 2012


Am Wed, 11. Jan 2012, 10:00:18 +0100 schrieb Oliver Sander:
> On second thoughts, why does the variable I write to have to be a member
> of a base class?  Just to avoid name conflicts?  It seems overly complicated
> to add an extra base class for UG_NS just to get a static variable.

We might at some point want to reimplement std::ignore from C++11.
UG_NS_Base::private offers some additional functionality, which may lead
sematic to conflicts as explained below, so I wanted to keep it private to UG.

> I am not sure we need this in dune-common.  Most set-but-unused warnings
> can probably be fixed, instead of needing a workaround.

This is actually inspired by a feature of the C++11 standard[1].  You can have
a function that returns a tuple, e.g.

  std::tuple<mode_t, off_t> get_file_attrs(const std::string &filename);

Now suppose you want to assign the file attributes to distinct variables.
this can be done by creating a tuple of references using tie():

  mode_t mode;
  off_t size;
  std::tie(mode, size) = get_file_attr(filename);

What if you aren't interested in the file mode, but only the size?  The
standard says that you can use the object std::ignore, like this:

  off_t size;
  std::tie(std::ignore, size) = get_file_attr(filename);

So why didn't I simply put this into <dune/common/tuples.hh>?

I can guarantee that extra functionality in a reimplentation in <tuples.hh>.
But if the compiler supports std::ignore natively, <tuples.hh> would just make
the native implementation available.

Now, the standard only specifies the behaviour of std::ignore in exactly the
case above (as an argument to std::tie()).  But in this case I'm using it
stand-alone, and thus I depend on functionality that the standard doesn't
actually guarantee[2].

For this reason I stuck to making 'ignore' private to UG.

Bye,
Jö.

[1] Actually, the last available draft n3242.

[2] Well, yes, any straight-forward implementation should be OK, but I can't
    rely on the implementation beeing straight-forward.  Or the implementation
    may spew warnings if I use it in a non-standard way.

-- 
Jorrit (Jö) Fahlke, Interdisciplinary Center for Scientific Computing,
Heidelberg University, Im Neuenheimer Feld 368, D-69120 Heidelberg
Tel: +49 6221 54 8890 Fax: +49 6221 54 8884

If God had intended Man to Smoke, He would have set him on Fire.
-- fortune
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 828 bytes
Desc: Digital signature
URL: <https://lists.dune-project.org/pipermail/dune/attachments/20120111/55fd8f66/attachment.sig>


More information about the Dune mailing list