lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] Delegating ctor uncalled for?


From: Vadim Zeitlin
Subject: Re: [lmi] Delegating ctor uncalled for?
Date: Thu, 9 Feb 2017 23:16:46 +0100

On Thu, 9 Feb 2017 17:14:10 +0000 Greg Chicares <address@hidden> wrote:

GC> On 2017-02-09 16:45, Vadim Zeitlin wrote:
GC> > On Thu, 9 Feb 2017 03:50:01 +0000 Greg Chicares <address@hidden> wrote:
GC> > 
GC> > GC> On 2017-02-04 15:23, Vadim Zeitlin wrote:
GC> > ..
GC> > GC> >  It's still simple enough to make a mistake with the order of these 
5
GC> > GC> > arguments. Maybe I just make too many mistakes, but I really 
appreciate
GC> > GC> > APIs which prevent me from making them, so I'd strongly prefer to 
be able
GC> > GC> > to write
GC> > GC> > 
GC> > GC> >     InputSequence sequence
GC> > GC> >             (expression
GC> > GC> >             ,InputParameters()
GC> > GC> >                     .years_to_maturity(y2m)
GC> > GC> >                     .issue_age(ia)
GC> > GC> >                     .retirement_age(ra)
GC> > GC> >                     .inforce_duration(id)
GC> > GC> >                     .effective_year(ey)
GC> > GC> >             );
GC> > GC> 
GC> > GC> but introducing a dependency on yet another library to accomplish this
GC> > GC> is not so good
GC> > 
GC> >  I might write another reply with some less trivial comments later, but 
for
GC> > now I just wanted to clarify what looks like a misunderstanding to me: the
GC> > syntax above does not require any third-party libraries and can, and
GC> > should, be implemented directly in InputParameters class itself, just as
GC> > it's done in e.g. wxFontInfo (which can be used to construct a wxFont
GC> > without checking the order of its parameters in the documentation).
GC> 
GC> That compiles?

 Yes, absolutely. It even works.

GC> I guess it must, because we already have:
GC> 
GC>     // Use a standard PDF Helvetica font (without embedding any custom 
fonts in
GC>     // the generated file, the only other realistic choice is Times New 
Roman).
GC>     pdf_dc.SetFont
GC>         (wxFontInfo(8).Family(wxFONTFAMILY_SWISS).FaceName("Helvetica")
GC>         );
GC> 
GC> Is this some new C++11 feature that I had never heard of, or some
GC> old feature that I'm too tired to recognize right now?

 This doesn't use any special language features at all, i.e. it has always
worked, even with CFront, I'd guess (although I'm not masochistic enough to
test it). It simply relies on returning a (non-const!) reference to the
object itself from all the setter functions, i.e. FaceName() above is
implemented like this:

        class wxFontInfo
        {
        public:
                wxFontInfo& FaceName(wxString const& facename)
                {
                        m_facename = facename;
                        return *this;
                }

        private:
                wxString m_facename;
        };

and then there is a wxFont(wxFontInfo const&) ctor which uses
wxFontInfo::m_facename and the other fields.

GC> If so, is it a C99 feature that isn't C++11 yet is supported
GC> by gcc even with '-std=c++11'?

 This is a perfectly cromulent C++98 (and before) feature that is, as this
thread shows, simply not as widely known as I think it deserves to be.

 Regards,
VZ


reply via email to

[Prev in Thread] Current Thread [Next in Thread]