Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3878548
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:37:31+00:00 2026-05-19T22:37:31+00:00

From Effective C++ by Scott Meyers: template<typename T, std::size_t n> class SquareMatrix: private SquareMatrixBase<T>

  • 0

From Effective C++ by Scott Meyers:

template<typename T, std::size_t n>
class SquareMatrix: private SquareMatrixBase<T> {

public:

    SquareMatrix( ) 
     : SquareMatrixBase<T>(n, 0), 
       pData(new T[n*n]) 
    {
         this->setDataPtr(pData.get()); 
    } 

        ...
private:

    boost::scoped_array<T> pData;
};

Regardless of where the data is
stored, the key result from a bloat
point of view is that now many — maybe
all — of SquareMatrix’s member
functions can be simple inline calls
to base class versions that are shared
with all other matrices holding the
same type of data, regardless of their
size. At the same time, SquareMatrix
objects of different sizes are
distinct types, so even though, e.g.,
SquareMatrix<double, 5> and
SquareMatrix<double, 1 0> objects use
the same member functions in
SquareMatrixBase<double>, there’s no
chance of passing a
SquareMatrix<double, 5> object to a
function expecting a
SquareMatrix<double, 1 0>. Nice, no?

Nice, yes, but not free. The versions
of invert with the matrix sizes
hardwired into them are likely to
generate better code than the shared
version where the size is passed as a
function parameter or is stored in the
object. For example, in the
size-specific versions, the sizes
would be compile-time constants, hence
eligible for such optimizations as
constant propagation, including their
being folded into the generated
instructions as immediate operands.
That can’t be done in the
size-independent version.

In above description in last paragraph it was mentioned as “hence eligible for such optimizations as constant propagation, including their being folded into the
generated instructions as immediate operands”. What does this statment mean? Kindly request to explain this.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:37:31+00:00Added an answer on May 19, 2026 at 10:37 pm

    Constant Propagation is a very simple (in the principle) optimization left to compilers.

    size_t radius = 5;
    size_t diameter = 2*radius;
    float perimeter = diameter * 3.1416f;
    

    This will be reduce by the compiler by propagating the constants:

    • notice that the value of radius is known
    • execute the computation of 2*radius (this is constant folding)
    • the value of diameter is therefore known
    • execute the computation of diameter * 3.1416f
    • the value of perimeter is therefore known

    The program is thus equivalent to:

    size_t radius = 5;
    size_t diameter = 10;
    float perimeter = 31.416f;
    

    Note that there are many other forms of optimization, for example, if radius and diameter are now no longer needed, we could remove them and only keep the perimeter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is from the item 16 of effective C++ 2nd edition scott meyers (page
Starting from Windows Server 2003, Windows included a new tool which calculates the effective
recently I've been reading through Scott Meyers's excellent Effective C++ book. In one of
The following code snippet is from book Effective C#, public event AddMessageEventHandler Log; public
In Scott Meyers's Effective C++ , item 18 Make interfaces easy to use correctly
Both Marshall Clines' C++ FAQ Lite and Scott Meyers' Effective C++ suggest using functions
Scott Meyers in his book Effective C++ says, To disallow functionality automatically provided by
I'm reading Scott Meyers' Effective C++ . He is talking about traits classes, I
Hey, what's the most effective way to remove beginning and ending slashes from all
From time to time I see an enum like the following: [Flags] public enum

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.