Noutați

Clang v15 compiler support coming to C++Builder 12

For C++ developers who want to take advantage of new ISO C++ language features in Clang v15 along with the power and productivity of RAD development using C++Builder, stay tuned to the Embarcadero blogs and C++Builder product website for news about the next release of C++Builder. Note: “This blog post is based on a pre-release version of the RAD Studio software and it has been written with specific permission by Embarcadero. No feature is committed until the product GA release.” David Millington, Embarcadero Product Manager, on August 31, 2023 presented a webinar titled “Behind the Build: RAD Studio and C++Builder 12.0” that previewed the upcoming Clang compiler upgrade and integration of Whole Tomato’s Visual Assist into the IDE.  You can watch the replay of the webinar at https://www.youtube.com/watch?v=B0Be_NFmEEE The next release of C++Builder with Clang v15 support will include the following toolchain enhancements: Clang: based on Clang 15, named ‘bcc64x’ C runtime: uses the Universal C Runtime (UCRT) C++ runtime: a new RTL, based on several open source areas STL: libc++ Linker: LLVM lld Debug format: PDB (with IDE support) The toolchain emits COFF object files and uses the Itanium ABI and mangling The default language standard is C++17 and C99 Here are two screen grabs from the August 31, 2023 David Millington webinar: Embarcadero Special Offer: Buy RAD 11.3 today and Apply to join the RAD 12 beta The promotional offer is ending soon (4 days left as of this blog post). Find out additional information at https://www.embarcadero.com/radoffer Keep Up To Date on C++Builder and ISO C++ To keep up to date on using C++Builder and the ISO C++ language you should absolutely bookmark and read everything that Yılmaz Yörü posts on his Embarcadero blog at https://blogs.embarcadero.com/author/yilmazyoru/ Yilmaz also has a great site for learning C++ at https://learncplusplus.org/ Stay tuned to the Embarcadero C++Builder product page for additional information and news.   Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder. Design. Code. Compile. Deploy. Start Free Trial   Upgrade Today    Free Delphi Community Edition   Free C++Builder Community Edition

Read More

MSVC Machine-Independent Optimizations in Visual Studio 2022 17.7

MSVC Machine-Independent Optimizations in Visual Studio 2022 17.7 Troy Johnson September 25th, 20232 3 This blog post presents a selection of machine-independent optimizations that were added between Visual Studio versions 17.4 (released November 8, 2022) and 17.7 P3 (released July 11, 2023). Each optimization below shows assembly code for both X64 and ARM64 to show the machine-independent nature of the optimization. Optimizing Memory Across Block Boundaries When a small struct is loaded into a register, we can optimize field accesses to extract the correct bits from the register instead of accessing it through memory. Historically in MSVC, this optimization has been limited to memory accesses within the same basic block. We are now able to perform this same optimization across block boundaries in many cases. In the example ASM listings below, a load to the stack and a store from the stack are eliminated, resulting in less memory traffic as well as lower stack memory usage. Example C++ Source Code: #include bool compare(const std::string_view& l, const std::string_view& r) {    return l == r; } Required Compiler Flags: /O2 X64 ASM: 17.4 17.7 sub        rsp, 56 movups  xmm0, XMMWORD PTR [rcx] mov        r8, QWORD PTR [rcx+8] movaps  XMMWORD PTR $T1[rsp], xmm0 cmp        r8, QWORD PTR [rdx+8] jne        SHORT $LN9@compare mov        rdx, QWORD PTR [rdx] mov        rcx, QWORD PTR $T1[rsp] call       memcmp test       eax, eax jne        SHORT $LN9@compare mov        al, 1 add        rsp, 56 ret        0 $LN9@compare: xor        al, al add        rsp, 56 ret        0 sub         rsp, 40 mov        r8, QWORD PTR [rcx+8] movups  xmm1, XMMWORD PTR [rcx] cmp        r8, QWORD PTR [rdx+8] jne         SHORT $LN9@compare mov        rdx, QWORD PTR [rdx] movq      rcx, xmm1 call        memcmp test        eax, eax jne         SHORT $LN9@compare mov        al, 1 add         rsp, 40 ret         0 $LN9@compare: xor         al, al add         rsp, 40 ret         0   ARM64 ASM: 17.4 17.7 str         lr,[sp,#-0x10]! sub         sp,sp,#0x20 ldr         q17,[x1] ldr         q16,[x0] umov        x8,v17.d[1] umov        x2,v16.d[1] stp         q17,q16,[sp] cmp         x2,x8 bne         |$LN9@compare| ldr         x1,[sp] ldr         x0,[sp,#0x10] bl          memcmp cbnz        w0,|$LN9@compare| mov         w0,#1 add         sp,sp,#0x20 ldr         lr,[sp],#0x10 ret |$LN9@compare| mov         w0,#0 add         sp,sp,#0x20 ldr         lr,[sp],#0x10 ret str         lr,[sp,#-0x10]! ldr         q17,[x1] ldr         q16,[x0] umov        x8,v17.d[1] umov        x2,v16.d[1] cmp         x2,x8 bne         |$LN9@compare| fmov        x1,d17 fmov        x0,d16 bl          memcmp cbnz        w0,|$LN9@compare| mov         w0,#1 ldr         lr,[sp],#0x10 ret |$LN9@compare| mov         w0,#0 ldr         lr,[sp],#0x10 ret   Vector Logical and Arithmetic Optimizations We continue to add patterns for recognizing vector operations that are equivalent to intrinsics or short sequences of intrinsics. An example is recognizing common forms of vector absolute difference calculations. A long series of bitwise instructions can be replaced with specialized absolute value instructions, such as vpabsd on X64 and sabd on ARM64. Example C++ Source Code: #include void s32_1(int * __restrict a, int * __restrict b, int * __restrict c, int n) { for (int i = 0; i < n; i++) { a[i] = (b[i] - c[i]) > 0 ? (b[i] – c[i]) : (c[i] – b[i]); } } Required Flags: /O2 /arch:AVX for X64, /O2 for ARM64 X64 ASM: 17.4 17.7 $LL4@s32_1: movdqu  xmm0, XMMWORD PTR [r11+rax] add     ecx, 4 movdqu  xmm1, XMMWORD PTR [rax] lea     rax, QWORD PTR [rax+16] movdqa  xmm3, xmm0 psubd   xmm3, xmm1 psubd   xmm1, xmm0 movdqa  xmm2, xmm3 pcmpgtd xmm2, xmm4 movdqa  xmm0, xmm2 andps   xmm2, xmm3 andnps  xmm0, xmm1 orps    xmm0, xmm2 movdqu  XMMWORD PTR [r10+rax-16], xmm0 cmp     ecx, edx jl      SHORT $LL4@s32_1 $LL4@s32_1: vmovdqu xmm1, XMMWORD PTR [r10+rax] vpsubd     xmm1, xmm1, XMMWORD PTR [rax] vpabsd     xmm2, […]

Read More

Livechatting cu FreshChat – soluția de pentru a crește vânzările, satisfacția și loialitatea clienților in 2023

Livechatting este o modalitate eficientă și interactivă de a comunica online cu clienții potențiali sau existenți ale afacerilor online (e-commerce). Dacă ești interesat de o soluție de livechatting care să îți ofere funcții avansate, integrări ușoare și rezultate măsurabile, atunci acest articol este pentru tine. În acest articol, îți vom prezenta soluția de livechatting FreshChat de la Freshworks, o platformă care îți permite să inițiezi conversații în timp real cu vizitatorii e-shopului, să le oferi suport, să le faci oferte și să le fidelizezi. Vei afla cum să alegi ediția potrivită pentru afacerea ta, cum să o configurezi pe site-ul tău web, cum să folosești funcțiile avansate de chatbot, omni-chanel comunicații, cum să monitorizezi și să analizezi performanța echipei de customer service, cum să o optimizezi pentru a îmbunătăți conversația cu clienții, La finalul articolului, vei înțelege cum te poate ajuta soluția de livechatting de la Freshworks să crești vânzările, satisfacția și loialitatea clienților. Introducere: ce este livechatting și de ce este important pentru afacerea ta Livechatting este o modalitate de a comunica online cu alte persoane prin intermediul unui sistem de chat online care permite conversații în timp real. Livechatting este important pentru un business online, mai ales pentru unul care se ocupă de e-commerce, deoarece îi poate ajuta să își atingă scopul de creștere a bazei de clienți și a numărului de comenzi. Iată cum: Platformele de livechatting oferă o modalitate eficientă și interactivă de a comunica online cu clienți potențiali și existenți, care îți poate aduce beneficii semnificative pentru afacerea ta de e-commerce. În continuare, îți vom prezenta soluția de livechatting de la Freshworks, o platformă completă și personalizabilă care îți permite să creezi conversații în timp real cu vizitatorii site-ului tău web. Freshworks: o soluție de livechatting completă și personalizabilă FreshChat de la Freshworks este o soluție de automatizare a procesului de comunicare conversațională, care îți ajută echipa de customer support să comunice mai ușor cu clienții pe mai multe canale, cum ar fi chat web, email, telefon și platforme de comunicare socială ca WhatsApp, Instagram sau iMessage. Cu ajutorul acestei platforme se pot crea diferite scenarii de interacțiunie cu vizitatorii unui e-shop, cum ar fi: FreshChat de la Freshworks îți permite să creați conversații personalizate și relevante cu clienții Dvs, care să ajute la creșterea ratei de conversie, satisfacția și loialitatea clienților. Opțiuni de omni-channel communication oferite de FreshChat Canalele de comunicare cu potențiali clienți oferiți de către platforma FreshChat sunt următoarele: FreshChat îți permite să conectezi oricare dintre aceste canale cu inboxul tău unificat, astfel încât să poți gestiona toate conversațiile cu clienții dintr-un singur loc. De asemenea, FreshChat îți oferă funcții avansate de chatbot, co-browsing, video și voce, care îți permit să automatizezi și să personalizezi conversațiile cu clienții. Funcționalități avansate de livechatting de la Freshworks Freddy este chatbot-ul inteligent de la Freshworks, care îți permite să automatizezi și să personalizezi conversațiile cu clienții tăi. Cu Freddy, poți să oferi suport clienților 24/7, să le oferi răspunsuri rapide și eficiente, să le rezolvi problemele și să le îndeplinești cererile. Freddy are următoarele beneficii pentru afacerea ta: Dacă vrei să afli mai multe despre Freddy, poți vizita pagina Freddy chatbot by Freshworks. Cum să monitorizezi și să analizezi performanța soluției de livechatting de la Freshworks: rapoarte, metrici și feedback Funcționalitățile de analitică a conversațiilor oferită […]

Read More

What Is Aggregate Member Initialization In C++?

The Aggregate Member Initialization is one of the features of C++. This feature is improved and modernized with C++11, C++14 and C++20. With this feature, objects can initialize an aggregate member from braced-init-list. In this post, we explain what the aggregate member initialization is and what were the changes to it in modern C++ standards. What is aggregate member initialization in modern C++? Aggregate initialization initializes aggregates. Since C++11, aggregates are a form of listed initializations. Since C++20 they are direct initializations. An aggregate could be an array or class type (a class, a struct, or a union).  Here is the general syntax,   T object = {arg1, arg2, …};   In C++11 and above, we use without = as below,   T object {arg1, arg2, …};   In C++20, there are 3 new options that we can use,   T object (arg1, arg2, …); T object = { .designator = arg1 , .designator { arg2 } … }; T object { .designator = arg1 , .designator { arg2 } … };   How to use aggregate member initialization in modern C++? C++14 provides a solution to problems in C++11 and above, for example in C++14, consider we have x, y coordinates in a struct, we can initialize them as below in a new xy object,   struct st_xy { float x, y; };   struct st_xy xy{ 3.2f, 5.1f };   In modern C++, consider that we have a struct that has a, b, c members. We initialize first two members as below,   struct st_x { short int a, b, c; };   struct st_x x{ .a = 10, .b = 20}; // x.c will be 0   We can directly initialize as below too,   struct st_y { int a = 100, b = 200, c, d; } y;   In C++17 and above, we can use this st_y as a base and we can add a new member to a new struct, then we can initialize as below,   struct st_z : st_y { int e; };   struct st_z z{ 1, 2, 3, 4, 5};   What restrictions are there for the aggregate member initialization in C++? If we consider the C++17 standard, an aggregate initialization can NOT be applied to a class type if it has one of the below, private or protected non-static data members, a constructor that is user-provided, inherited, or explicit constructors (explicitly defaulted or deleted constructors are allowed), base class or classes (virtual, private, protected), virtual member functions If we consider the C++20 standard, an aggregate initialization can NOT be applied to a class type if it has one of the below, private or protected non-static data members, user-declared or inherited constructors, base class or classes (virtual, private, protected), virtual member functions Is there a full example of aggregate member initialization in C++? Here is a full example that explains simply most used features of aggregate member initialization, 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42   #include   // Aggregate in C++14 struct st_xy { float a, b; };   struct st_xy xy{ 3.2f, 5.1f };   struct st_x { […]

Read More

Will ChatGPT Replace Human Software Developers? Probably Not

Since the release of ChatGPT, there has been a great deal of hype around generative AI and how companies can leverage it to cut costs and democratize software and application development. Naturally, with discussions of cost-cutting and democratization come whispers about what will happen to software developers. This is a real and valid concern, but software developers’ skills, expertise and creativity are still very much needed. While generative AI and AI code generation tools like ChatGPT have shown some promise and potential benefits, they are still in their infancy—like many other innovative technological advancements. We also don’t know what scenarios they may present down the road or their true abilities when the technology matures. For instance, how will it integrate with other technologies? We don’t know what will happen when a ChatGPT-generated line of code breaks or needs to be changed. We don’t know if it can provide a novel solution to a unique problem or what security threats it will present. Given these unknowns, technology executives should think twice about replacing experienced and creative technology talent, such as software developers, with AI code generators. Will ChatGPT create novel code to solve a unique problem never encountered before? Probably not. A Tale as Old as Time (Or at Least a Decade) The technology industry has been searching for and developing new ways to make certain software development tasks much easier and more streamlined for years. One example of this is low-code/no-code. The notion of simplifying application development and replacing software developers with laypeople (citizen developers) has been around for more than a decade now, as low-code and no-code solutions have grown more popular. These solutions have promised that companies don’t need technical talent to get their software and app projects off the ground. However, if you look at the impact of these solutions today, their use can result in large amounts of technical debt and almost always require the skill of experienced software developers. The reason? Building complex software and applications is extremely difficult; it’s an art. Low-code and no-code solutions have their rightful place and can make things easier if a company is looking to launch a simple app or static web page. These solutions can increase the pace of development and time-to-market and enable everyday people without any development skills to facilitate them. However, they are not actually a complete solution and often overlook aspects of development that a human software developer would typically address. Without a skilled expert involved, low-code/no-code platforms often can’t solve a unique problem a company has. So, how does this relate to AI code generators like ChatGPT? Here’s how. A Similar Situation—With One Key Difference When thinking about their place in the development process, AI code generators are not that different from low-code or no-code solutions. The thinking is that they will also enable non-technical individuals to create software and applications with ease. Yet, there is one key difference—they promise expertise, too. But is the expertise coming from the AI code generator or the person piloting it? The answer is simple; it is not from the code generator. There have been examples of companies and individuals that have tried using ChatGPT to build code, and they have appeared to be successful. However, without the input of the individuals using it, it never would […]

Read More

Google De-Recruits 100s of Recruiters ¦ ARM Valued at $45½B in IPO

Welcome to The Long View—where we peruse the news of the week and strip it to the essentials. Let’s work out what really matters. This week: Google fires hundreds of recruiters, and ARM gets a sky-high valuation. 1. Layoffs for the recruiters themselves First up this week: Google’s hiring has slowed to such an extent that it has far too many in-house recruiters. Boo hoo? Analysis: Don’t shed a tear at task shedding I get it. Many reading this care little for the typical recruiter. All too often they seem like pointless brokers—adding no value to the process yet receiving a huge bonuses. But this news is the latest indication that DevOps jobs are harder to come by. Louise Matsakis has the scoop: Google lays off hundreds on recruiting team “Hard decision”Google is laying off hundreds of people across its global recruiting team as hiring at the tech giant continues to slow. … Workers who were laid off began learning their roles had been eliminated earlier today, according to posts on social media.…Google began reducing the speed of its hiring last year, after adding tens of thousands of workers in 2020 and 2021. … Google spokesperson Courtenay Mencini said, … “In order to continue our important work to ensure we operate efficiently, we’ve made the hard decision to reduce the size of our recruiting team.” Bring in the RecruitBot 4000. galaxytachyon explains: How likely is it that this is because of AI taking over the jobs? Sift through resumes, contact candidates, schedule some interviews, connect the hiring manager to the candidate, even getting some extra information from the candidate via email or phone calls are all things an LLM can efficiently do. They may actually do it even better than a regular human, since they might “know” more about the role and the technical requirements than an average [recruiter]. AI recruiters—and AI developers, too. Here’s Qbertino: I don’t expect those jobs to return. … After 23 years in IT I’m looking into a … career switch myself. Our industry is fully industrialized, custom coding is by now only for mostly totally broken legacy **** that will be replaced by SOA subscriptions within the next few years and what’s still left to code will be mostly done by AI quite soon I suspect.…Time to move on. It was an awesome ride but we’ve now finally built the bots that will replace us. Nice. This will spell more wealth for everyone in the long run even if we are out of cushy jobs with obscene salaries. When Google catches a cold, do other DevOps shops sneeze? Not in gijames1225’s experience: It’s weird being at a midsize company that has only accelerated hiring for engineers while the big players all go through these layoff cycles. The cynic in me sees them as token displays of fiscal responsibility being made for shareholders and a weird performativity of not wanting to be outdone by other tech giants. Another bit of me wonders about general productivity at these places if they can layoff so many people and nothing really appears to change (from a consumer perspective). All of which makes this Anonymous Coward wonder: I wonder what happens now to those who have threatened to quit or were reluctant to come in to physical offices. Meanwhile, u/saracenraider has questions: Do […]

Read More

CloudBees CEO: State of Software Development is a Disaster

CloudBees CEO Anuj Kapur told attendees at a DevOps World event today that with developers spending only 30% of their time writing code the current state of software development in enterprise IT organizations is a disaster. After more than 14 years of effort, the promise of DevOps—in terms of being able to accelerate the rate at which applications are being deployed—remains largely academic, said Kapur. In fact, the effort to shift more responsibility for application security further left toward developers has only increased the amount of cognitive load and reduced the amount of time available to write code, he noted. However, with the rise of generative artificial intelligence (AI), an inflection point that will dramatically increase the velocity at which applications are being built and deployed has arrived, said Kapur. The challenge will be achieving that goal without increasing the cognitive load on developers. That cognitive overload results in 70% of developers’ time not being productive within organizations that often hire thousands of developers, he noted. Despite all the DevOps issues that need to be addressed, AI advances promise improvement. The overall DevOps market is still relatively young, given the current level of adoption, said Kapur. “We continue to believe the market is early,” he said. Today, CloudBees took the wraps off the first major update to the open source Jenkins continuous integration/continuous delivery (CI/CD) platform to have been made in the past several years. At the same time, the company also unveiled a DevSecOps platform based on Kubernetes that is optimized for building and deploying cloud-native applications based on portable Tekton pipelines. That latter platform provides the foundation through which CloudBees will, in the months ahead, apply generative AI to software engineering to, for example, create unit tests on the fly and automate rollbacks. In addition, DevSecOps capabilities will be extended all the way out to the integrated development environments (IDE) to reduce the cognitive load of developers. The overall goal is to reduce the number of manual processes that create bottlenecks that make it challenging to manage DevOps at scale. Criticism of the level of developer productivity enabled by DevOps compared to other development approaches needs to be tempered, said Tapabrata Pal, vice president of architecture for Fidelity Investments, because it still represents a significant advance. There is still clearly too much toil, but the issues that impede the pace at which developers can effectively write code tend to be more cultural than technical, he added. Organizations are not inclined to automatically trust the code created by developers, so consequently, there is still a lot of friction in the DevOps process, noted Pal. In theory, advances in AI should reduce that friction, but it’s still early days in terms of the large language models (LLMs) that drive generative AI platforms and their ability to create reliable code, he added. That should improve as LLMs are specifically trained using high-quality code, but in the meantime, the pace at which substandard code might be generated could overwhelm DevOps processes until AI is applied there as well, said Pal. Thomas Haver, master software engineer for M&T Bank, added that while assisted AI technologies will have a major impact, it’s not reasonable to expect large organizations to absorb them overnight. Patience will be required to ensure advances are made in ways that […]

Read More

JFrog swampUP: Addressing the Advent of AI

At JFrog SwampUp 2023, the buzz with all about AI, especially with JFrog’s announcement of Machine Learning (ML) Model Management capabilities. These conversations around AI and ML reflected these technologies’ growing influence and importance in the DevOps world. How much of the generative AI conversation is just hype, though? And what does that mean for AI and ML as a whole? Alan Shimel, CEO of Techstrong Group, and I sat down with Stephen Chin, VP of DevRel at JFrog, to find out. As far as Chin is concerned, even as more companies create and leverage AI models, these models must be managed like any other software component. Chin said JFrog Artifactory acts as a staging ground to operationalize models using DevSecOps best practices. Algorithms and models will continue to grow in size and complexity, and they will require robust processes around deployment and management – just like any other software artifact. The key, Chin said, is to think of ML as just another development language and leverage tools that standardize and streamline working with it. Compared to traditional enterprise applications, though, DevOps workflows for AI/ML are still relatively immature, but Chin said JFrog’s new model management capabilities aim to provide that missing automation and governance using DevSecOps best practices for governance, security, and licensing compliance. Additionally, Chin noted that AI/ML have become essential for development teams to keep up with the explosive demand for code. At this point, AI has become table stakes. In the AI arms race, the winners are those who understand AI has become a vital development tool to enhance productivity. In terms of job security, the losers are the ones who can’t keep up with the volume of code. According to Chin, you are out of the running if you don’t embrace AI. Looking ahead, AI will not make developers obsolete, though – quite the opposite. Given the quasi-unlimited appetite for new code, Chin emphasized that developers who embrace AI will have more work than ever. One way to think of it is that AI provides a new form of “outsourcing” to boost human productivity, much like previous waves of innovation in computer science. When it comes to security, there are still challenges that need to be addressed; code generated by today’s AI solutions still has significant drawbacks like potential data bias, lack of explainability and simple errors. In the long term, though, Chin believes AI itself will provide the solution to secure an exponentially growing codebase, given its superior scale. Just as AI will make individual developers more productive, it can also supercharge security teams – but it can also empower bad actors. The key will be continuing to democratize the benefits to even the playing field. AI promises to be a transformative technology on the scale of the Bronze Age or Quantum computing, Chin said, but the path forward will require humans and machines working together to ensure it’s used for good. It’s clear that the pace of innovation in AI and ML is rapidly accelerating. As these technologies become further democratized and integrated into developer workflows, they promise to transform how software is built and secured, Chin said. Companies must take advantage of this technology innovation by providing the pipelines and governance for this software revolution, he added. Chin believes the future will […]

Read More

Learn To Use Generalized Lambda Captures In C++

Impact-Site-Verification: 9054929b-bb39-4974-9313-38176602ccee The Lambda Expression construct is introduced in C++ 11 and further developed in the C++14, C++17, and C++20 standards. C++14 standard introduced the generalized lambda capture (init capture) that allows you to specify generalized captures, it allows to use move capture in lambdas. In C++14, lambda expressions are improved by the generalized lambda (generic lambda) and by this generalized lambda captures. In this post, we explain how to use generalized lambda captures in modern C++ What is a lambda in C++? A Lambda Expression defines an anonymous function or a closure at the point where it is used. You can think of a lambda expression as an unnamed function (that’s why it’s called “anonymous”). Lambda expressions help make code cleaner, and more concise and allow you to see behavior inline where it’s defined instead of referring to an external method, like a function. Lambda Expressions are an expression that returns a function object, and they are assignable to a variable whose data type is usually auto and defines a function object. The syntax for a lambda expression consists of specific punctuation with = [ ] ( ) { … } series. If you are new to lambdas or want to know more about them, please check these two posts that we released before. How to use a generalized lambda function in C++ Before C++14, lambda function parameters need to be declared with concrete types, as in the given example above. C++14 has a new generic lambda feature that allows lambda function parameters to be declared with the auto-type specifier. The basic syntax of a Lambda Expression in C++ is; Datatype Lambda Expression = [Capture Clause] (Parameter List) -> Return Type { Body } Generalized lambdas can be defined with the auto keyword that comes with C++11. We can define a generic lambda with the auto keyword as below. auto add_things = []( auto a, auto b ) {    return a + b; }; We can use this lambda with an int type, int x = add_things( 10, 20 ); or we can use it with a float type, float f = add_things( 10.f, 20.f ); or we can use it with bool, char, double, long long double,… etc types. This is why it is called as ‘generalized‘, it is a general form that we can use with any types. Very useful and powerful. What are generalized lambda captures in C++? The Lambda Expression construct is introduced in C++ 11 and further developed in the C++14, C++17, and C++20 standards. C++14 standard introduced the generalized lambda capture (also known as init capture) that allows you to specify generalized captures. In C++14, lambda expressions are improved by the generalized lambda (generic lambda) and by this generalized lambda captures, it allows to use move capture in lambdas. A generalized capture is a new and more general capture mechanism, it allows us to specify the name of a data member in the closure class generated from the lambda, and an expression initializing that data member. Lambdas can capture expressions, rather than just variables as in functions, and this feature allows lambdas to store move-only types. How to use generalized lambda captures in C++ Let’s see how we can use generalized lambda captures in modern C++, std::move can be used to move objects in lambda captures as below, struct […]

Read More

What Is Auto Return Type Deduction In C++?

C++11 allowed lambda functions to deduce the return type based on the type of the expression given to the return statement. The C++14 standard provides return type deduction in all functions, templates, and lambdas. C++14 allows return type deduction for functions that are not of the form return expressions. In this post, we explain the auto keyword, what is an auto type deduction, and how we can use it in functions, templates, and lambdas. Here are some very simple examples. What is the auto keyword in C++? The auto keyword arrives with the new features of the C++11 standard and above. It can be used as a placeholder type specifier (an auto-typed variable), or it can be used in a function declaration, or a structured binding declaration. The auto keyword can be used with other new CLANG standards like C++14, C++17, etc. Here is a simple example of how to use auto-typed variables in C++.   unsigned long int L;   auto a = L; // a is automatically unsigned long int   The auto keyword was being used as an automatic data specifier (storage class specifier) until C++11. This feature was removed by the C++11 standard. What is auto return type deduction in C++? In object oriented programming, type inference or deduction means the automatic detection of the data type of an expression and its conversion to a new type in a programming language and auto return type deduction may deduce return. type (i.e. float parameters to int return values). By the C++14 standard, we can use auto return type deduction in functions, templates, in lambdas. Now let’s see some simple examples that show how we can use them. If you want to use return type deduction in functions, templates, and lambdas, it must be declared with auto as the return type, but without the trailing return type specifier in C++11. The auto return type deduction feature can be used with parameter types in functions. Here is a simple example,   auto sq(int r)   // auto return type deduction in function { return r*r; }   The auto return type deduction feature can be used on modified parameters. Here is a simple example.   auto inc(int r)  // auto return type deduction in function { return ++r; }   The auto return type deduction feature can be used with references in functions.   auto& zero(int& r) // auto return type deduction in function { r = 0; return r; }   The auto return type deduction can be used with templates. Here is an example:   template auto template_sq(T t) // auto return type deduction in template { return (int)(t*t); // deduce to int }   The auto keyword is very useful in lambda declarations and it has an auto return type deduction feature too. See a simple lambda example below.   auto lambda_sq = [](int r)  // auto return type deduction in lambda { return r*r; };   Note that one of the important differences between lambdas and normal functions is that normal functions can refer to themselves by name but lambdas cannot. Is there a full example of auto return type deduction in C++? Here is a full example about auto return type deduction in functions, a template and a lambda. 1 2 3 4 5 6 7 8 9 10 11 […]

Read More