Templates are a powerful C++ feature that allows programmers to write generic and reusable code by abstracting type information. Templates provide type-safe containers and algorithms without runtime overhead. They allow writing functions and classes that work across built-in and user-defined types. While templates increase reusability and performance, their syntax can be complex and compiler errors difficult to understand, requiring significant effort to write robust and reusable template code.
This is Work-In-Progress. Developing a series of lectures on C++0x. This will augment my presentations on C++ and Design Pattern. First trial run was done at Interra, Noida in 2009
This is Work-In-Progress. Developing a series of lectures on C++0x. This will augment my presentations on C++ and Design Pattern. First trial run was done at Interra, Noida in 2009
In
computer
programming languages
, indentation formats program
source code
to
improve readability.
P
rogramming languages make
use of i
ndentation to define program
structure .
Programmers
use
indent
ation
to
understand
the structure of their programs to human
readers. Especially
, inden
tation is the
better way to
represent
the relationship between
control flow
constructs such as selection statements
or
loops and code contained within and outside
them.
This
paper describes about different indentation styles
used in Programming and also describes context of each indentation s
tyle. It also describes indentation
styles used for various
programming constructs and t
he best practice for a particular programming
construct.
This
paper helps the beginners to understand various indentation styles used in programming
and also to ch
oose
suitable indentation style
C++ Basics introduction to typecasting Webinar Slides 1Ali Raza Jilani
This Webinar is conduct by Learn 4 Earn Team
(Ali Raza Jilani & Hamza Ashraf)
In this Webinar Students can Prepare Mid Terms Exam of C++ and Insha Allah they will Get best Grades.
in the first discuss about Basics of C++
You can be Able to improve your Basics because if you have Strong basics then you can solve a big problem ion finger tips.
I hope you will learn much more new today
Technical and scientific applications dealing with a high computational load today face the challenge to match the increasingly parallel nature of current and future hardware. The talk shows how the increased complexity of software can be controlled by using generic programming technologies. The process and its advantages are introduced using many concrete examples, starting from simple operations on sequences (like sum/reduce or local filters), then moving into higher-dimensional applications like image processing and finally to particle methods based on dynamic neighborhood graphs.
In
computer
programming languages
, indentation formats program
source code
to
improve readability.
P
rogramming languages make
use of i
ndentation to define program
structure .
Programmers
use
indent
ation
to
understand
the structure of their programs to human
readers. Especially
, inden
tation is the
better way to
represent
the relationship between
control flow
constructs such as selection statements
or
loops and code contained within and outside
them.
This
paper describes about different indentation styles
used in Programming and also describes context of each indentation s
tyle. It also describes indentation
styles used for various
programming constructs and t
he best practice for a particular programming
construct.
This
paper helps the beginners to understand various indentation styles used in programming
and also to ch
oose
suitable indentation style
C++ Basics introduction to typecasting Webinar Slides 1Ali Raza Jilani
This Webinar is conduct by Learn 4 Earn Team
(Ali Raza Jilani & Hamza Ashraf)
In this Webinar Students can Prepare Mid Terms Exam of C++ and Insha Allah they will Get best Grades.
in the first discuss about Basics of C++
You can be Able to improve your Basics because if you have Strong basics then you can solve a big problem ion finger tips.
I hope you will learn much more new today
Technical and scientific applications dealing with a high computational load today face the challenge to match the increasingly parallel nature of current and future hardware. The talk shows how the increased complexity of software can be controlled by using generic programming technologies. The process and its advantages are introduced using many concrete examples, starting from simple operations on sequences (like sum/reduce or local filters), then moving into higher-dimensional applications like image processing and finally to particle methods based on dynamic neighborhood graphs.
CS 23001 Computer Science II Data Structures & AbstractionPro.docxfaithxdunce63732
CS 23001 Computer Science II: Data Structures & Abstraction
Project #4
Spring 2015
Objectives:
· Develop and use a Tree ADT (n-ary)
· Apply and use tree traversal algorithms
· Manipulate trees by inserting and deleting nodes
· Apply and use STL
Problem:
Build a program profiler. Construct a program to instrument C++ source code to support program profiling.
It is often important to determine how many times a function or statement is executed. This is useful not only for debugging but for determining what parts of a program may need to be optimized. This process is called profiling. That is, a execution profile presents how many times each part of a program is executed using a given set of input data (or for some run time scenario). To compute a profile, statements need to be added to the code that keep track of how many times a function or statement is executed. The process of adding these statements is called instrumenting the code.
To implement a profiler one must first parse the source code and generate an Abstract Syntax Tree (AST) of the code. Each node of the AST describes the syntactic category of the code stored within it (function, statement, while-statement, etc.). So at the top level is a syntactic category corresponding to a program, class, or function (such as in the case of a main). Under that are sub-trees that further detail the syntactic categories of each part of the code. Such things as declarations, parameter lists, while-statement, and expression statements will describe the various parts of the program.
After the AST is generated it can then be traversed and the appropriate syntactic structures can be found that need to be instrumented. Once a construct is found, say a function, new code can be inserted that keeps track of how many times that function is executed.
The most difficult part of constructing a profiler is correctly parsing the source code. Unfortunately, C++ is notoriously difficult to parse. So here we will use a parsing tool called src2srcml. This tool reads in C++ code and marks up the code with XML tags (e.g., block, if, while, condition, name, etc). That is, the output is an AST in XML. The XML representation is called srcML (source code markup language).
A number of srcML data files are provided for the project. However, you can use your own program as input. To run srcML on wasp or hornet you will first need to set a PATH variable so the command can be found. You need to execute the command:
export PATH=/local/opt/srcml/bin:$PATH
It is best if you insert this line into your .bash_profile file in your home directory on wasp/hornet.
Then to generate the srcML file for your own code use the following:
src2srcml main.cpp -o main.cpp.xml
Use the following for a list of all options:
src2srcml --help
More information about srcML can be found at www.srcML.org including a list of all the tag names (see Getting Started). You can also download srcML if you want it on your own machine.
Your .
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...Rowank2
In-depth C programming language interview questions are covered in this post, covering questions on pointers, memory management, data structures, and other advanced subjects. The questions are designed to evaluate the candidate's knowledge of the language's intricacies and sophisticated elements. Candidates can better their language skills and be ready for forthcoming interviews by going through these questions.
Do you want to learn basic information about the c Language?
Yes!
That’s great.
This pdf is the right choice for you.
Here, I will provide you all the basic information about C language.
You can visit our blog to enjoy our original post.
Almost everything can be done using refactoring tools:
* How to get buy-in for refactoring? (use Technical Debt quantification tools)
* How to identify refactoring candidates? (use smell detection tools)
* How to prioritize / identify what to refactor first? (use reports from design analysis tools)
* How do I identify dependencies and evaluate impact of refactoring? (use visulization tools)
* How to I actually perform refactoring? (Use IDE support for automated refactoring and use them!)
Deriving from a rich experience in using tools for refactoring in real-world projects, this talk takes you through a whirl-wind tour of refactoring tools (of course for Java). What's more, this talk includes quick demos of some of these tools so you can see them in action.
Presented in BoJUG meetup on 19th Jan in Bangalore - https://www.meetup.com/BangaloreOpenJUG/events/257183518/
Please check out the workshop "AI meets Blockchain" at HIPC 2018, in Bangalore: http://hipc.org/ai-blockchain/
HIPC is a premier conference and hence getting a paper accepted in HIPC workshop would be quite an accomplishment for any blockchain/AI enthusiast. Check out the details in this poster on submissions.
I have been fortunate to have worked with some geeks with incredible coding skills. I felt amazed at how they can play games with compilers, perform magic with their incantations on the shell, and solve some insanely complex algorithm problems with ease. I naively assumed that they are going to achieve greatness in near future. Alas, I was wrong. Really wrong. [Read the rest of the article ... ]
Many students reach out to me asking for project ideas they can do as a summer project for learning. Here is an interesting project idea - implement your own java disassembler (and expand it to a VM later).
Design Patterns - Compiler Case Study - Hands-on ExamplesGanesh Samarthyam
This presentation takes a case-study based approach to design patterns. A purposefully simplified example of expression trees is used to explain how different design patterns can be used in practice. Examples are in C#, but is relevant for anyone who is from object oriented background.
This presentation provides an overview of recently concluded Bangalore Container Conference (07-April-2017). See www.containerconf.in for more details.
Bangalore Container Conference 2017 (BCC '17) is the first conference on container technologies in India happening on 07th April. Organizations are increasingly adopting containers and related technologies in production.Hence, the main focus of this conference is “Containers in Production”. This one-day conference sets the perfect stage for container enthusiasts, developers, users and experts to meet together and learn from each others experiences.
Presented in Bangalore Open Java User Group on 21st Jan 2017
Awareness of design smells - Design comes before code. A care at design level can solve lot of problems.
Indicators of common design problems - helps developers or software engineers understand mistakes made while designing and apply design principles for creating high-quality designs. This presentation provides insights gained from performing refactoring in real-world projects to improve refactoring and reduce the time and costs of managing software projects. The talk also presents insightful anecdotes and case studies drawn from the trenches of real-world projects. By attending this talk, you will know pragmatic techniques for refactoring design smells to manage technical debt and to create and maintain high-quality software in practice. All the examples in this talk are in Java.
Bangalore Container Conference 2017 (BCC '17) is the first conference on container technologies in India. Organizations are increasingly adopting containers and related technologies in production. Hence, the main focus of this conference is “Containers in Production”. This one-day conference sets the perfect stage for container enthusiasts, developers, users and experts to meet together and learn from each others experiences.
This presentation covers quiz questions prepared for the Core Java meetup on 1st October in Accion Labs. It has questions from "Java best practices", "bytecodes", and "elastic search".
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
A tale of scale & speed: How the US Navy is enabling software delivery from l...sonjaschweigert1
Rapid and secure feature delivery is a goal across every application team and every branch of the DoD. The Navy’s DevSecOps platform, Party Barge, has achieved:
- Reduction in onboarding time from 5 weeks to 1 day
- Improved developer experience and productivity through actionable findings and reduction of false positives
- Maintenance of superior security standards and inherent policy enforcement with Authorization to Operate (ATO)
Development teams can ship efficiently and ensure applications are cyber ready for Navy Authorizing Officials (AOs). In this webinar, Sigma Defense and Anchore will give attendees a look behind the scenes and demo secure pipeline automation and security artifacts that speed up application ATO and time to production.
We will cover:
- How to remove silos in DevSecOps
- How to build efficient development pipeline roles and component templates
- How to deliver security artifacts that matter for ATO’s (SBOMs, vulnerability reports, and policy evidence)
- How to streamline operations with automated policy checks on container images
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionAggregage
Join Maher Hanafi, VP of Engineering at Betterworks, in this new session where he'll share a practical framework to transform Gen AI prototypes into impactful products! He'll delve into the complexities of data collection and management, model selection and optimization, and ensuring security, scalability, and responsible use.
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
Keynote at DIGIT West Expo, Glasgow on 29 May 2024.
Cheryl Hung, ochery.com
Sr Director, Infrastructure Ecosystem, Arm.
The key trends across hardware, cloud and open-source; exploring how these areas are likely to mature and develop over the short and long-term, and then considering how organisations can position themselves to adapt and thrive.
PHP Frameworks: I want to break free (IPC Berlin 2024)Ralf Eggert
In this presentation, we examine the challenges and limitations of relying too heavily on PHP frameworks in web development. We discuss the history of PHP and its frameworks to understand how this dependence has evolved. The focus will be on providing concrete tips and strategies to reduce reliance on these frameworks, based on real-world examples and practical considerations. The goal is to equip developers with the skills and knowledge to create more flexible and future-proof web applications. We'll explore the importance of maintaining autonomy in a rapidly changing tech landscape and how to make informed decisions in PHP development.
This talk is aimed at encouraging a more independent approach to using PHP frameworks, moving towards a more flexible and future-proof approach to PHP development.
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfPaige Cruz
Monitoring and observability aren’t traditionally found in software curriculums and many of us cobble this knowledge together from whatever vendor or ecosystem we were first introduced to and whatever is a part of your current company’s observability stack.
While the dev and ops silo continues to crumble….many organizations still relegate monitoring & observability as the purview of ops, infra and SRE teams. This is a mistake - achieving a highly observable system requires collaboration up and down the stack.
I, a former op, would like to extend an invitation to all application developers to join the observability party will share these foundational concepts to build on:
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfPeter Spielvogel
Building better applications for business users with SAP Fiori.
• What is SAP Fiori and why it matters to you
• How a better user experience drives measurable business benefits
• How to get started with SAP Fiori today
• How SAP Fiori elements accelerates application development
• How SAP Build Code includes SAP Fiori tools and other generative artificial intelligence capabilities
• How SAP Fiori paves the way for using AI in SAP apps
1. An Introduction to C++ Templates
Why Templates?
Generic programming has become a dominant programming paradigm in C++, particularly after
the incorporation of the Standard Template Library (STL) as part of the standard library in 1996.
Templates - the language feature that supports generic programming in C++ - was originally
conceived for supporting ‘parameterized types’ (classes parametrized by type information) in
writing container classes.
Templates are a compile time mechanism. Because of this, there is no runtime overhead
associated with using them. Also, using templates is completely type safe. Templates help to
seamlessly integrate all types and thereby let programmers write code for one (generic) type. So,
it serves as a mechanism for writing high-level reusable code, which is known as ‘generic
programming’. Like the structured, modular and object oriented programming approaches,
generic programming is another programming approach (and C++ supports all these four
programming paradigms! For this reason, C++ is referred to as a ‘multi-paradigm’ language).
Writing Reusable Code
Two primary means of providing reusable functionality in conventional object-oriented systems is
through inheritance and composition. Inheritance refers to creating subclasses or subtypes from
existing classes and composition refers to providing objects of other class types as data
members. quot;Parameterized types give us a third way (in addition to class inheritance and object
composition) to compose behavior in object-oriented systems. Many designs can be
implemented using any of these three techniquesquot;, observes [Gamma et al, 1994]. Templates
look at the problem of reusability in a different way - it uses type independence as the basis
rather than inheritance, polymorphism and composition.
One of the main objectives of C++ is to support writing low-level code for systems programming
in which performance is an important consideration. C++ templates do not add any additional
performance overheads and still promises high level of reusability; hence, templates have
become very important in C++ for writing reusable code.
Use of Templates
The (re)use of tested and quality template code can save us from lots of programming effort and
can be helpful in variety of programming tasks. The three important advantages of using
templates are:
• type safety (as strict type checking is done at compile time itself),
• reusability (as writing code for one generic type is enough) and
• performance (as templates involve no runtime overheads).
There are many other advantages of using templates and they are discussed in detail later in this
article.
To illustrate the usefulness of templates, let us take an example from the C standard library. To
get the absolute value of a number we need different functions, one for each type. For integers
we use abs, for floating point numbers fabs, and for complex numbers cabs. If polymorphic
facilities were available in C, such inventing of new names would not have been necessary (and
life could have been easier for the programmer). How about using overloading in C++ for this
problem? Consider:
2. int abs(int);
long abs(long);
double abs(double);
complex abs(complex);
Yes, in this case, we need not reinvent new names, but still almost same code is duplicated in
these functions; so, overloading is not a very good solution.
How about using overriding? No, it cannot help us in for this requirement since these functions
differ in their argument and return type, and overriding requires that the signature remains the
same.
Using templates could elegantly solve this problem. Using function templates, it is enough to write
generic code for one function:
template <class T>
T abs(T arg) {
return ((arg < 0) ? –arg : arg);
}
With this definition, the compiler will take care of creating copies (known as template instantiation)
for specific types as and when required in the program. For example, when given abs(12) or
abs(doubleVar), the compiler is smart enough to instantiate (or make use of the one if already
instantiated) the right function for that type and resolve it in the compile time itself.
In the beginning of the article, we mentioned that templates started with the desire to
quot;parameterizequot; the containers. Such classes are known as ‘class templates’. A simple example
would be a stack container parameterized by type T instead of providing separate classes like
int_stack, string_stack, double_stack etc:
template <class T>
class stack {
// the following members remain the same
stack(int start_size = 10);
stack(const stack&);
stack& operator=(const stack&);
~stack();
int is_empty() const;
int is_full() const;
// templatizing these members using T
void push(const T& t);
T& pop();
private:
T* stack; // Note T* here
int topOfStack; // following data members remain the same
int size;
};
Templates can provide readymade implementations even for day-to-day programming activities
(for example, consider std::for_each function template in STL); hence it frees the
programmer from reinventing the wheel and allows him to straightaway reuse what is available in
templates.
Templates make it possible to write truly reusable components that can be modified with little
3. difficulty, still retaining type safety (ensuring type safety is an important objective of strongly typed
languages).
Template Meta-programming
Let us take another example to see from different perspective. An important advantage of C++
templates is its unimaginably expressive and powerful nature. Here is a simple (and well-known)
example of template version of finding factorial of a number:
template <int num>
struct Factorial {
static const int fact =
num * Factorial < num - 1 > :: fact;
};
// specialization for 0, which provides terminating condition
template <>
struct Factorial<0> {
static const int fact = 1;
};
int main() {
std::cout<< quot;The factorial of 3 is: quot; << Factorial<3>::fact;
}
// output:
// The factorial of 3 is: 6
Remember that template mechanism is a compile-time mechanism in C++. In this program, there
is a template for Factorial with non-type parameter int. There is a template specialization of
Factorial for value 0 - template instantiation is done for 3, 2, 1 and terminates at 0 as there is
a specialization available. For finding the factorial of 3, with template instantiation, the value is
found at compile-time itself! This approach of programming is known as meta-programming,
which is an emerging programming approach in C++.
Meta-programming is a difficult topic and it is possible to write sophisticated programs which do
compile-time manipulations. Boost is a set of open-source libraries, mostly written based on
meta-programming approach. The factorial example given in this section is just for introducing the
topic and we’ll not cover it anymore in this article; if you are interested, please see the Boost
website (www.boost.org) for more details.
Advantages of Using Templates
Templates abstract type information (and non-type information too)
You can use primitive types, class types or templates themselves as arguments: in this way,
templates offer maximum flexibility in their use. Consider:
template <int lines, int columns>
class screen {
char ** buffer;
explicit screen(lines, columns) {
buffer = new char[lines * columns];
}
// other members
4. };
typdef screen<24, 80> text_screen;
type_screen my_screen;
Here, the non-type arguments are used to specify the number of rows and columns in a screen. A
typical text screen might be made up of 24 lines and 80 columns. If you want to change the
dimensions of screen, you can instantiate a new screen type by providing new dimensions. In this
way, the screen template offers flexibility in providing the dimensions of the screen.
Templates provide readymade components for both generic and specific uses
How will you design a container for a simple dictionary? Given a string as key (the word for which
meaning needs to be found), a mapping should be provided to locate the list of strings (as
meanings of the word). For this purpose, you can provide a new typedef of the standard map
template provided in the C++ standard library:
typedef map< string, list<string> > dictionary;
A map template has a <key, value> pair and you can search for values using the key. In this
instantiation of map template, string is the key type holding the word to be searched and a
list<string> is the type that has the list of meanings for the words. So, this instantiation solves our
problem. Since templates can take other templates as arguments, this becomes a powerful tool
for design with minimal need to write your own code or to customize according to your need
(though it is possible to customize STL containers and algorithms).
Templates provide compact reusable code
Template code can be very compact compared to the code written using conventional approach
of writing reusable software using inheritance hierarchies in C++. For example, STL is a compact
library if compared to a library providing similar functionality with conventional inheritance based
approach.
Problems with Templates
Though the templates provide significant benefits in the form of writing reusable code, there are
significant problems that can put even experienced C++ programmers into trouble. Here is a
small list of problems in using templates.
The syntax for using templates is clumsy
The syntax for template is somewhat clumsy and for code of significant complexity sometimes
makes the code very difficult to understand. Particularly the meta-programming techniques tend
to result in quite complex and unreadable code.
Difficulty in understanding compiler error messages
The error messages for templates, in most of the cases, are very difficult to understand and
comprehend. Even simple mistakes in template usage can result in incomprehensible error
messages. Though the situation should improve with the compilers slowly maturing with better
template support, the current state of the quality of the error messages that the compiler can emit
is less than satisfactory.
It takes considerable effort to write reusable components
5. Understanding and writing template code is complex simply because of the fact that writing
reusable code is inherently difficult. Note that only writing template code that is difficult; using
templates is quite easy. In fact, it is quite possible to use templates without understanding that
they are in fact templates! For example, many of the C++ programmers use std::string without
knowing that it is a template! std::string is a typedef of:
std::basic_string< char, std::char_traits< char >,
std::allocator< char > >
Almost entire C++ standard library (only with some exceptions) make use of templates.
Parameterized Types in Java and C#
Type parameterization (known as ‘generics’ feature) is supported in many well known statically
typed languages, including ML, Ada, Eiffel, Java and C#. In these languages, generics is meant
for providing ‘type safe containers’. However, in C++, the support for templates is very
sophisticated and entire libraries are often written using templates feature extensively. Also, the
applications of templates in C++ are beyond the simple idea of writing type safe containers. For
example, it is possible to write sophisticated meta-programs (an introduction was given in this
article), but that is not possible with languages like Java or C#.
In the next article
In this article, we saw a technical overview of the powerful templates feature in C++. In the follow-
up article next month, we’ll see various language features for supporting templates in C++.
References
[Gamma et al, 1994] Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides, “Design
Patterns: Elements of Reusable Object-Oriented Software”, Addison-Wesley, 1994
S.G. Ganesh is a research engineer in Siemens (Corporate Technology). He has
authored a book “Deep C” (ISBN 81-7656-501-6). You can reach him at
sgganesh@gmail.com.