![]() |
|
|
Welcome to the { mindfrost82.com } forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Who discovered the type erasure technique in C++?
I am wondering who first figured out how to do this in C++ ?
Boost::Function and Boost::Expressive libraries both use it and my Castor library (mpprogramming.com/cpp) also relies on it very heavily. I thought Eric Niebler might be the one, but at NWCPP he told me that he too had picked it up from somewhere else. IMHO, this is one of the most significant discoveries done in the library space ... with a lot unrealized potential. -Roshan -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|||
|
Re: Who discovered the type erasure technique in C++?
On 17 août, 16:48, "Roshan Naik" <naikr...@gmail.com> wrote:
> I am wondering who first figured out how to do this in C++ ? Isn't it simply dynamic dispatch with value semantics? -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|||
|
Re: Who discovered the type erasure technique in C++?
On Aug 17, 3:48 pm, "Roshan Naik" <naikr...@gmail.com> wrote:
> I am wondering who first figured out how to do this in C++ ? > Boost::Function and Boost::Expressive libraries both use it and my Castor > library (mpprogramming.com/cpp) also relies on it very heavily. I thought > Eric Niebler might be the one, but at NWCPP he told me that he too had > picked it up from somewhere else. I saw this idiom first in boost::any which, I guess, one of the oldest boost libraries. Max -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|||
|
Re: Who discovered the type erasure technique in C++?
On 17 Aug, 15:48, "Roshan Naik" <naikr...@gmail.com> wrote:
> I am wondering who first figured out how to do this in C++ ? > Boost::Function and Boost::Expressive libraries both use it and my Castor > library (mpprogramming.com/cpp) also relies on it very heavily. I thought > Eric Niebler might be the one, but at NWCPP he told me that he too had > picked it up from somewhere else. I have never heard of type erasure in C++. I have come across it in java though. I always thought it was there for compatibility with containers before java had generics. What exactly does it mean in C++ please? Regards, Andrew Marlow -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|||
|
Re: Who discovered the type erasure technique in C++?
marlow.andrew@googlemail.com wrote:
> On 17 Aug, 15:48, "Roshan Naik" <naikr...@gmail.com> wrote: >> I am wondering who first figured out how to do this in C++ ? >> Boost::Function and Boost::Expressive libraries both use it and my Castor >> library (mpprogramming.com/cpp) also relies on it very heavily. I thought >> Eric Niebler might be the one, but at NWCPP he told me that he too had >> picked it up from somewhere else. > > I have never heard of type erasure in C++. I have come across it in > java though. I always thought it was there for compatibility with > containers before java had generics. What exactly does it mean in C++ > please? > > Regards, > > Andrew Marlow Without being called as such, it's of use in the implementation of Variant (www.oonumerics.org/tmpw01/alexandrescu.pdf, see also three subsequent articles http://www.erdani.org/publications/cuj-04-2002.html, http://www.erdani.org/publications/cuj-06-2002.html, http://www.erdani.org/publications/cuj-08-2002.html). What gives it away in C++ is a type with a template constructor that uses the type to create a dynamically polymorphic object. Andrei -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|||
|
Re: Who discovered the type erasure technique in C++?
{ Edits: top-posting rearranged; re top-posting see FAQ item 5.4. -mod }
On Mon, 18 Aug 2008 13:55:17 -0700, Mathias Gaunard <loufoque@gmail.com> wrote: > On 17 août, 16:48, "Roshan Naik" <naikr...@gmail.com> wrote: >> I am wondering who first figured out how to do this in C++ ? > > Isn't it simply dynamic dispatch with value semantics? yes .. but I consider both those aspects as "side effects" of the implementation. In other words.. it is not a description of the feature but a description of how it is made to work. -Roshan -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|||
|
Re: Who discovered the type erasure technique in C++?
{ Edits: top-posting rearranged; re top-posting see FAQ item 5.4. -mod }
On Mon, 18 Aug 2008 17:42:31 -0700, <marlow.andrew@googlemail.com> wrote: > > I have never heard of type erasure in C++. I have come across it in > java though. I always thought it was there for compatibility with > containers before java had generics. What exactly does it mean in C++ > please? > > Regards, > > Andrew Marlow Here is how I would describe type erasure in the context of C++ : Lets say T denotes all types that meet some criteria C. And C is known at compile time. This criteria can be something like "has member function foo()". So type erasure is about defining a type C where we encode this criteria and achieve the following goal : Lets say we have two types MyT and HisT which ,in addition to fulfilling the criteria C, can potentially have other members. struct MyT { void foo(); void sayHi(); }; struct HisT { void foo(); void bar(); void sayHello(); }; Note that MyT and HisT do not derive from anything and there are no conversion operators defined to can convert MyT and HisT to C. Also type C does not know about the existence of MyT and HisT. But we should be able to : C erase1 = MyT(); // no casting reqd ! C erase2 = HisT(); C erase3 = std::string("hello"); // Compiler error : string::foo() not found! erase1.foo(); // calls MyT::foo() erase2.foo(); // calls HisT::foo() erase2.sayHello(); // compiler error After the values have been assigned to erase1 and erase2 the original type info is now lost (or erased) and thus we are limited to operating only on member foo(). All we know for certain after the assignment is that original types implemented member foo. This is similar to being able to assign a pointer of a derived class to a pointer of a base class. But the key difference with type erasure, is that type C does not need to be authored prior to authoring MyT and HisT. So MyT and HisT are not tightly coupled to C. With C++ duck typing, we could perhaps achieve something close but only if this code that resides inside a templated type or function having C as type parameter. I apologize if this description is not very easy to understand. -Roshan -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|||
|
Re: Who discovered the type erasure technique in C++?
On 19 août, 11:58, "Roshan Naik" <naikr...@gmail.com> wrote:
> Lets say T denotes all types that meet some criteria C. And C is known at > compile time. > This criteria can be something like "has member function foo()". So type > erasure is about > defining a type C where we encode this criteria and achieve the following > goal That's actually dynamic structural subtyping. That's a special case of type erasure. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|||
|
Re: Who discovered the type erasure technique in C++?
Roshan Naik wrote:
> Here is how I would describe type erasure in the context of C++ : > > Lets say T denotes all types that meet some criteria C. And C is known > at compile time. > This criteria can be something like "has member function foo()". So > type erasure is about > defining a type C where we encode this criteria and achieve the > following goal : If defined that way, then "type erasure" is an attempt to copy Haskell's type classes, introduced 1989 by Wadler & Blott. Marco -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|||
|
type erasure vs witness (was Re: Who discovered the type erasure technique in C++?
On 08/19/08 04:58, Roshan Naik wrote:
[snip] > > Here is how I would describe type erasure in the context of C++ : > > Lets say T denotes all types that meet some criteria C. And C is known at > compile time. > This criteria can be something like "has member function foo()". So type > erasure is about > defining a type C where we encode this criteria and achieve the following > goal : > > > Lets say we have two types MyT and HisT which ,in addition to fulfilling > the criteria C, can potentially have other members. > > struct MyT { > void foo(); > void sayHi(); > }; > > struct HisT { > void foo(); > void bar(); > void sayHello(); > }; > > Note that MyT and HisT do not derive from anything and there are no > conversion operators defined to can convert MyT and HisT to C. Also type C > does not know about the existence of MyT and HisT. > > But we should be able to : > > C erase1 = MyT(); // no casting reqd ! > C erase2 = HisT(); > C erase3 = std::string("hello"); // Compiler error : string::foo() not > found! > > erase1.foo(); // calls MyT::foo() > erase2.foo(); // calls HisT::foo() > erase2.sayHello(); // compiler error [snip] > I apologize if this description is not very easy to > understand. > > -Roshan > Roshan, I've just been reading about Haskell Open Witnesses: http://semantic.org/stuff/Open-Witnesses.pdf So far, I only understand part of what a Witness is; however, it sounds somewhat like your description. for example, at the top of Section 2 of the .pdf there's: A witness is a value that witnesses some sort of constraint on some list of type variables. The constraint in your example is that the types must contain a foo() method. So, my question is, *is* there some similarity between type erasure in c++ and haskell witnesses? I thought this would be useful since the .pdf file also mentioned GADT: http://research.microsoft.com/~akenn...cs/gadtoop.pdf and several months(maybe years) ago someone on this list wondered why there was no GADT library. It would be nice if someone these different concepts could be related. -Larry -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
![]() |
|
| Thread Tools | Search this Thread |
| Display Modes | |
|
|