Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

tr1::function implementation

4 views
Skip to first unread message

santiago...@gmail.com

unread,
Aug 31, 2007, 6:46:05 PM8/31/07
to
About two years ago I came across somebody's public implementation of
the tr1::function (and tr1::result_of) on the web. It was much more
straightforward than the GNU or Boost version (it only allowed up to 2
arguments). It helped me learn a lot about template specialization
and I'd like to know who the author was. The problem is I can't find
it anymore no matter how I search. By the way it is NOT any of the
following similar versions:

Tiny Template Library:
http://www.codeproject.com/cpp/TTLFunction.asp

Anthony Williams, ACCU:
http://accu.org/index.php/journals/436

Thiago R. Adams:
http://paginas.terra.com.br/informatica/thiago_adams/tr1functional.htm

Andrei Alexandrescu's Functor from LOKI:
http://loki-lib.sourceforge.net/

Not GNU and not Boost!

Has anybody seen any other public implementations?

Thanks


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Thiago Adams

unread,
Sep 3, 2007, 8:42:53 AM9/3/07
to
{ Edits: quoted banner removed. Please don't quote the banner. Tip:
most Usenet client programs remove the banner automatically. -mod }

By the way it is NOT any of the
> following similar versions:
>
> Tiny Template Library:http://www.codeproject.com/cpp/TTLFunction.asp
>
> Anthony Williams, ACCU:http://accu.org/index.php/journals/436
>
> Thiago R. Adams:http://paginas.terra.com.br/informatica/thiago_adams/tr1functional.htm
>
> Andrei Alexandrescu's Functor from LOKI:http://loki-lib.sourceforge.net/
>
> Not GNU and not Boost!
>
> Has anybody seen any other public implementations?

Hi,
The code that I have published is not difficult to understand.
I suggest you remove the macros and create a version for 1 or 2
arguments. The code will be much easier to understand. If you have
questions about the implementation you can send me an email.

Some years ago (before I knew about tr1::function) I talked with some
people that were implementing a similar code. Nowadays, there is
nothing at tr1::function that I would like to change. That is because
I have implemented it.

I look forward to see this class at C++. It is a very useful class
with a great design.

Thiago R. Adams

Douglas Gregor

unread,
Sep 4, 2007, 10:13:53 AM9/4/07
to
On Aug 31, 6:46 pm, "santiago.ander...@gmail.com"

<santiago.ander...@gmail.com> wrote:
> About two years ago I came across somebody's public implementation of
> the tr1::function (and tr1::result_of) on the web. It was much more
> straightforward than the GNU or Boost version (it only allowed up to 2
> arguments). It helped me learn a lot about template specialization
> and I'd like to know who the author was. The problem is I can't find
> it anymore no matter how I search. By the way it is NOT any of the
> following similar versions:
[snip]

This probably isn't what you found before, but implementations of
tr1::function based on variadic templates are quite a bit cleaner than
other implementations, because one definition of function suffices for
any number of arguments. No macros (BOOST_FUNCTION_TEMPLATE_PARAMS;
ick!), no numbered versions (Functor1, Functor2, etc.), but you'll
need a C++0x compiler :)

Variadic templates are described here:

http://www.generic-programming.org/~dgregor/cpp/variadic-templates.html

Appendix A.2 of the "variadic templates proposal" (in the
documentation section) contains a nearly complete implementation of
tr1::function using variadic templates. It's less than 2 pages long.

- Doug

santiago...@gmail.com

unread,
Sep 7, 2007, 7:05:53 PM9/7/07
to
Yes, I imagine variadic templates would have been very useful when I
attempted to implement the tr1::bind() function.

In any case, I would like to return to the tr1::function
implementation - I wrote an implementation based on this unknown
author's design, then I modified it to more closely resemble the
structure of the LOKI Functor implementation because it had fewer
template specializations. I didn't include the unknown author's
copyright in the file at the time (though I know I should have). Now
I'm afraid I'll have to scrap the code because I can't find the
author's name and copyright info.

While searching to learn about copyright issues, I found this post:
<http://groups.google.com/group/comp.lang.c++/browse_thread/thread/
2d764c0dbe849d5a/f88f2118af587fbf?
lnk=gst&q=copyright&rnum=17#f88f2118af587fbf>.

I find the reply statement by Pete Becker agreeable:
"Copyright covers the expression of an idea. You can use the idea all
you
like; you cannot copy and publish the author's words (or code),
unless
there's no other reasonable way to express the idea."

So in this moral dilemma, I find myself asking questions such as:

- Even if I started with the unknown author's code as a reference, can
I merely put the LOKI copyright on it because that's what the code has
evolved into (the exact same structure minus the typelists)? More
specifically, in my version and in the LOKI version, there's no
template specialization of the interface class (i.e. function or
Functor), no template specialization of the derived class(es), and one
template specialization of the base "invoker" class for each number of
arguments. The other implementations generally make template
specializations for all the classes (including the unknown author's
implementation). And instead of using a typelist to find the
arguments of a function signature, I wrote a separate
func_type<signature> metaprogram with many specializations to extract
the return type and argument types. It still uses an EmptyType like
the LOKI library.
- What parts of the code are ideas that cannot be expressed in other
reasonable ways?
The 4 links that I posted in the start of the thread all use the same
virtual function mechanism for hiding the underlying function type.
The only real difference is the way in which the class templates are
specialized. Although, I understand the Boost version gets around the
virtual function call somehow. So are there other "expressions" that
are reasonable? Or am I stuck with mimicking the Boost mechanism or
the virtual function mechanism, both of which may be infringement?
Also, every implementation must end up using some sort of template
specilization to accept all sorts of function signatures. The LOKI
implementation uses the unique typelists, but the rest seem very
similar. Additionally, all of the "derived-invoker" implementations
use a clone function, which is really necessary to implement a copy
operation for that design. So is using a clone function further
infringment? In other words, can this be reasonably done another way?
- Which of these implementations that I mention in the first posting
can be considered similar enough for a claim of copyright
infrigement? They all use a similar interface/derived-invoker
structure except the Boost implementation. Did all the authors think
of this independently, or did some of the authors see another
implementation before doing their own? I can honestly say I couldn't
come up with the "derived-invoker" mechanism on my own. And I don't
entirely understand the Boost implementation yet.

I would be sad to have to throw away the code because I cannot find
the unknown author's name or copyright requirements. Even if its okay
not to include the unknown author's copyright notice (since it more
closely resembles the LOKI design), then I would still like to mention
his name as a contributor.
The other alternative is to start over with one of the above
implementations and adapt it to fit my needs and FOLLOW the copyright
directions this time.

Bo Persson

unread,
Sep 8, 2007, 4:44:17 PM9/8/07
to
santiago...@gmail.com wrote:
::
:: I find the reply statement by Pete Becker agreeable:

:: "Copyright covers the expression of an idea. You can use the idea
:: all you
:: like; you cannot copy and publish the author's words (or code),
:: unless
:: there's no other reasonable way to express the idea."

Yes, that's pretty straight forward. You can do things that others
have done before, you can even look at the code to see how it is done,
but you cannot "reuse" the code (unless the copyright holder gives his
permission).

You have to write your own code yourself!

:: So in this moral dilemma, I find myself asking questions such as:


::
:: - Even if I started with the unknown author's code as a reference,

Does "as a reference" mean that you glanced at the code on a web site,
or that you used the actual code as "your" code?

:: can I merely put the LOKI copyright on it because that's what the


:: code has evolved into (the exact same structure minus the
:: typelists)?

No, Loki copyright is for Loki code, not for everythinh that looks
similar.

And even if you put someone else's copyright in you code, you still
need the copyright holder's permission to use it!

:: - What parts of the code are ideas that cannot be expressed in
:: other reasonable ways?

No part of the code is ideas, it is an expression of an idea!

I think Pete meant that if you write your own code, and it happens to
look exactly like someone else'e code, that is ok, IF that is the only
way to express this particular idea.

For example, if you are to display a popup window, the GUI manual says
that you have to call a set of interface functions in a specific
order. If you and I were to do that, our code would certainly call the
same functions in the same order. That would be ok, as it is just
about the only reasonable way to do that.

:: Additionally,


:: all of the "derived-invoker" implementations use a clone function,
:: which is really necessary to implement a copy operation for that
:: design. So is using a clone function further infringment? In
:: other words, can this be reasonably done another way? -

Clone functions has been around a lot longer than tr1. Using old ideas
is ok. Copying code with old ideas, is not!

:: Which of


:: these implementations that I mention in the first posting can be
:: considered similar enough for a claim of copyright infrigement?
:: They all use a similar interface/derived-invoker structure except
:: the Boost implementation. Did all the authors think of this
:: independently, or did some of the authors see another
:: implementation before doing their own? I can honestly say I
:: couldn't come up with the "derived-invoker" mechanism on my own.

You don't have to reinvent the wheel each time you write some code.
Unless there is some nasty patent around, looking at public code or
disussing the ideas with other implementors is quite ok. Happen all
the time.

You are not allowed to COPY the code, but you are allowed to write
something similar on your own. Pete's comment about "no other
reasonable way" comes into play when you actually do write your own
code, but it still turns out to be very similar to someone else's. At
that point, you might have to show that this is the obvious way to do
it.


Bo Persson

Jerry Coffin

unread,
Sep 8, 2007, 10:42:54 PM9/8/07
to
In article <1189197343.8...@19g2000hsx.googlegroups.com>,
santiago...@gmail.com says...

[ ... ]

> I find the reply statement by Pete Becker agreeable:
> "Copyright covers the expression of an idea. You can use the idea all
> you like; you cannot copy and publish the author's words (or code),
> unless there's no other reasonable way to express the idea."

It's a little more complicated than that. Copyright covers not only
their expression of the idea, but any "derived works". Unfortunately,
it's a bit difficult to figure out exactly where to draw the line
between being inspired by something, and deriving from it...

> - Even if I started with the unknown author's code as a reference, can
> I merely put the LOKI copyright on it because that's what the code has
> evolved into (the exact same structure minus the typelists)?

I'd say that if you have something that evolved from his code, it's
still a derived work, even if it's evolved to the point that the
relationship to the original is barely recognizable.

[ ... ]

> The other alternative is to start over with one of the above
> implementations and adapt it to fit my needs and FOLLOW the copyright
> directions this time.

That's probably safest.

--
Later,
Jerry.

The universe is a figment of its own imagination.

Andrei Alexandrescu (See Website For Email)

unread,
Sep 10, 2007, 3:30:56 PM9/10/07
to
Bo Persson wrote:
> santiago...@gmail.com wrote:
> ::
> :: I find the reply statement by Pete Becker agreeable:
> :: "Copyright covers the expression of an idea. You can use the idea
> :: all you
> :: like; you cannot copy and publish the author's words (or code),
> :: unless
> :: there's no other reasonable way to express the idea."
>
> Yes, that's pretty straight forward. You can do things that others
> have done before, you can even look at the code to see how it is done,
> but you cannot "reuse" the code (unless the copyright holder gives his
> permission).
>
> You have to write your own code yourself!
>
> :: So in this moral dilemma, I find myself asking questions such as:
> ::
> :: - Even if I started with the unknown author's code as a reference,
>
> Does "as a reference" mean that you glanced at the code on a web site,
> or that you used the actual code as "your" code?
>
> :: can I merely put the LOKI copyright on it because that's what the
> :: code has evolved into (the exact same structure minus the
> :: typelists)?
>
> No, Loki copyright is for Loki code, not for everythinh that looks
> similar.

Definitely. What I try doing most of the time when I inspire myself from
somewhere is to put a comment containing a pointer to the source of
inspiration. That's actually selfish :o). The pointer is very useful for
finding further detail later on.

> And even if you put someone else's copyright in you code, you still
> need the copyright holder's permission to use it!

Loki's and many other libraries' copyright only mentions that copying
verbatim without explicit permission is fine as long as the top comment
is preserved.


Andrei

santiago...@gmail.com

unread,
Sep 13, 2007, 6:27:51 PM9/13/07
to
> Does "as a reference" mean that you glanced at the code on a web site,
> or that you used the actual code as "your" code?

I looked at the code on a website. I did not use the actual code as
my code: I typed it on my own, but when I got stuck I went back to
look at how something was done. I may have used the same identifiers
or syntax a couple of times. The structure was not exactly the same
either.

> No, Loki copyright is for Loki code, not for everythinh that looks
> similar.

Then I saw the advantages in Loki's Functor code, and I changed
everything to be like that code, except what they already had in
common, which I left in, and minus the TypeList, which I solved in a
manner different from both codes. Now there is nothing that is
similar to the unknown author's code, except perhaps: using a normal
pointer instead of an auto_ptr (like Loki), an identifier name or two,
and a clone function (and of course, what the two implementations
already had in common). I don't consider an identifier name nor the
clone function copyrightable (the clone function was the "obvious
way").

So, now that there's nothing significant from the other code that is
not also in the Loki code, then why should I have to use this other
author's copyright? If I were to derive from the Loki code again, my
derivation would be exactly the same as it is now, except it would
have an auto_ptr and more clever clone function.

AND, since the way the it is done in Loki is not the obvious way nor
the only way to do it, then I should include the Loki copyright
because it is derived from Loki code, right?

0 new messages