C++C++14C++17Learn C++Syntax

What Is The Integer Sequence (std::integer_sequence) In C++ 14

What Is The Integer Sequence stdinteger sequence In C++ 14

In modern programming sometimes we want to use a sequence of integers that are created at compile-time. In C++14, the std::integer_sequence is a class template for the sequence of integers that is generated at compile-time. In this post, we explain what integer sequence (std::integer_sequence) is in modern programming.

What is the integer sequence (std::integer_sequence) in C++ 14?

In C++14, the std::integer_sequence is a class template defined in a header that can be used for the sequence of integers generated at compile-time. In some cases, looping through a range of numbers whose span is unknown is used and, in these cases, we can use the std::integer_sequence integer sequence. Thus, we can create a sequence of integers at compile time. Our application knows the sequence of integers before it runs, and we use them on runtime as a package. In other words, the std::integer_sequence is used to hold a sequence of integers which can be turned into a parameter pack. We can use integer_sequence in template programming or meta-programming algorithms, and this will make our code faster and less complex.

In C++14, a simple syntax for the std::integer_sequence can be written as shown below.

Here, T is the type of integers and val is a parameter pack of integers.

Is there a simple integer sequence (std::integer_sequence) example in C++ 14?

Here is a simple example how we can use std::integer_sequence.

Here is another example with std::initializer_list.

Is there a full integer sequence (std::integer_sequence) example in C++ 14?

Here is a full integer sequence (std::integer_sequence) example in C++14 and C++17.

For more information, please see https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3658.html

What Is The Integer Sequence stdinteger sequence In C++ 14 C++ Builder logo

C++ Builder is the easiest and fastest C and C++ compiler and IDE for building simple or professional applications on the Windows operating system. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Introduction to C++Learn C++Syntax

Learn Default Constructors Of Classes In Modern C++

Artificial Intelligence TechC++C++11C++14C++17Learn C++

How To Develop Special AI Activation Functions In C++?

Artificial Intelligence TechC++C++11C++14C++17Language FeatureLearn C++

Learn How To Read The WAV Waveform Audio File Format In C++

C++C++11Learn C++

What Is Assignment Operator Overloading?