c++

Create C++ Member Function in Visual Studio

We are excited to announce that Create C++ Member Function can now be used to quickly add constructor and in Visual Studio 17.6 Preview 2. When you have a class with fields, you can add a default constructor, constructor with all fields, equality operator, and . Three dots will appear below a class name to indicate that you can add a member function, and you can hover over them to see the quick action (screwdriver icon). When the default constructor and equality operator are added respectively, the Go to Definition of the operator== is displayed below, showing that the body of the   You can also choose to add a constructor with all fields and an equality operator with all fields respectively, and the Go to Definition will show that the operator== has all the field comparisons.     Future Work This experimental feature will be improved by adding more functions that can save you a lot of typing. Right now, it includes constructor and operator==and we are considering adding more cases,   We have a Developer Community ticket to Improve “Create Member Function”, if you have the same suggestions make sure to upvote it.   Send us your feedback!  Download the latest version of Visual Studio Preview and give the Create C++ Member Function feature a try. Your feedback will be extremely helpful in shaping this experience, therefore, please continue to send your feedback in the comments below or/and via Developer Community. You can also reach us on Twitter (@VisualC), or via email at visualcpp@microsoft.com.   

Read More

C++23’s New Fold Algorithms

C++20 added new versions of the standard library algorithms which take ranges as their first argument rather than iterator pairs, alongside other improvements. However, key algorithms like std::accumulate were not updated. This has been done in C++23, with the new std::ranges::fold_* family of algorithms. The standards paper for this is P2322 and was written by Barry Revzin. It been implemented in Visual Studio 2022 version 17.5. In this post I’ll explain the benefits of the new “rangified” algorithms, talk you through the new C++23 additions, and explore some of the design space for fold algorithms in C++. Background: Rangified Algorithms C++20’s algorithms make several improvements to the old iterator-based ones. The most obvious is that they now can take a range instead of requiring you to pass iterator pairs. But they also allow passing a “projection function” to be called on elements of the range before being processed, and the use of C++20 concepts for constraining their interfaces more strictly defines what valid uses of these algorithms are. These changes allow you to make refactors like: // C++17 algorithm cat find_kitten(const std::vector& cats) { return *std::find_if(cats.begin(), cats.end(), [](cat const& c) { return c.age == 0; }); } // C++20 algorithm cat find_kitten(std::span cats) { return *std::ranges::find(cats, 0, &cat::age); } The differences here are: Instead of having to pass cats.begin() and cats.end(), we just pass cats itself. Since we are comparing a member variable of the cat to 0, in C++17 we need to use std::find_if and pass a closure which accesses that member and does the comparison. Since the rangified algorithms support projections, in C++20 we can use std::ranges::find and pass &cat::age as a projection, getting rid of the need for the lambda completely. These improvements can greatly clean up code which makes heavy use of the standard library algorithms. Unfortunately, alongside the algorithms which reside in the header, there are also several important ones in the header, and these were not rangified in C++201. In this post we’re particularly interested in std::accumulate and std::reduce. accumulate and reduce std::accumulate and std::reduce are both fold operations. They “fold” or “reduce” or “combine” multiple values into a single value. Both take two iterators, an initial value, and a binary operator (which defaults to +). They then run the given operator over the range of values given by the iterators, collecting a result as they go. For instance, given std::array arr = {1,2,3}, std::accumulate(begin(arr), end(arr), 0, std::plus()) will run (((0 + 1) + 2) + 3). Or std::accumulate(begin(arr), end(arr), 0, f) will run f(f(f(0, 1), 2), 3). These functions are both what are called left folds because they run from left to right. There’s also right folds, which as you may guess, run from right to left. For the last example a right fold would look like f(1, f(2, f(3, 0))). For some operations, like +, these would give the same result, but for operations which are not associative (like -), it could make a difference. So why do we have both std::accumulate and std::reduce? std::reduce was added in C++17 as one of the many parallel algorithms which let you take advantage of parallel execution for improved performance. The reason it has a different name than std::accumulate is because it has different constraints on what types and operations you can use: namely the […]

Read More

Functional exception-less error handling with C++23’s optional and expected

This post is an updated version of one I made over five years ago, now that everything I talked about is in the standard and implemented in Visual Studio. In software things can go wrong. Sometimes we might expect them to go wrong. Sometimes it’s a surprise. In most cases we want to build in some way of handling these misfortunes. Let’s call them disappointments. std::optional was added in C++17 to provide a new standard way of expressing disappointments and more, and it has been extended in C++23 with a new interface inspired by functional programming. std::optional expresses “either a T or nothing”. C++23 comes with a new type, std::expected which expresses “either the expected T, or some E telling you what went wrong”. This type also comes with that special new functional interface. As of Visual Studio 2022 version 17.6 Preview 3, all of these features are available in our standard library. Armed with an STL implementation you can try yourself, I’m going to exhibit how to use std::optional‘s new interface, and the new std::expected to handle disappointments. One way to express and handle disappointments is exceptions: void pet_cat() { try { auto cat = find_cat(); scratch_behind_ears(cat); } catch (const no_cat_found& err) { //oh no be_sad(); } } There are a myriad of discussions, resources, rants, tirades, and debates about the value of exceptions123456, and I will not repeat them here. Suffice to say that there are cases in which exceptions are not the best tool for the job. For the sake of being uncontroversial, I’ll take the example of disappointments which are expected within reasonable use of an API. The Internet loves cats. Suppose that you and I are involved in the business of producing the cutest images of cats the world has ever seen. We have produced a high-quality C++ library geared towards this sole aim, and we want it to be at the bleeding edge of modern C++. A common operation in feline cutification programs is to locate cats in a given image. How should we express this in our API? One option is exceptions: // Throws no_cat_found if a cat is not found. image_view find_cat (image_view img); This function takes a view of an image and returns a smaller view which contains the first cat it finds. If it does not find a cat, then it throws an exception. If we’re going to be giving this function a million images, half of which do not contain cats, then that’s a lot of exceptions being thrown. In fact, we’re pretty much using exceptions for control flow at that point, which is A Bad Thing™. What we really want to express is a function which either returns a cat if it finds one, or it returns nothing. Enter std::optional. std::optional find_cat (image_view img); std::optional was introduced in C++17 for representing a value which may or may not be present. It is intended to be a vocabulary type — i.e. the canonical choice for expressing some concept in your code. The difference between this signature and the previous one is powerful; we’ve moved the description of what happens on an error from the documentation into the type system. Now it’s impossible for the user to forget to read the docs, because the compiler is reading them for us, […]

Read More

vcpkg 2023.04.15 Release: vcpkg ships in Visual Studio, Xbox triplets, GitHub Actions Cache Support, and More…

The 2023.04.15 release of the vcpkg package manager is available. This blog post summarizes changes from February 25th, 2023 to April 15th, 2023 for the Microsoft/vcpkg, Microsoft/vcpkg-tool, and Microsoft/vcpkg-docs GitHub repos. Some stats for this period: 39 new ports were added to the open-source registry. If you are unfamiliar with the term ‘port’, they are packages that are built from source and are typically C/C++ libraries. 957 updates were made to existing ports. As always, we validate each change to a port by building all other ports that depend on or are depended by the library that is being updated for our nine main triplets. There are now 2,190 total libraries available in the vcpkg public registry. 125 contributors submitted PRs, issues, or participated in discussions in the repo. The main vcpkg repo has over 5,300 forks and 18,400 stars on GitHub.   Notable Changes vcpkg now included with Visual Studio IDE As of Visual Studio 2022 (version 17.6), vcpkg is now added by default for IDE installations that include C++ workloads. Visual Studio users can run vcpkg commands from a Developer Command Prompt for Visual Studio targeting a new version of the IDE – both the ones embedded in the IDE as well as external terminals. You must run vcpkg integrate install to configure the built-in copy of vcpkg as the one for use by the IDE and in order to add enable MSBuild and CMake integration. More details will be shared in a separate blog post (coming soon!).   vcpkg now supports targeting Xbox out of the box with four new community triplets. The appropriate triplet is automatically chosen when using the Gaming.Xbox.*.x64 custom platforms in the Microsoft GDK with Xbox Extensions via the vcpkg integrate functionality. This makes it easy for developers to build open-source dependencies for this platform. Thank you to Chuck Walbourn from the Xbox organization for preparing these triplets. Triplet Description x64-xbox-scarlett Builds DLLs for Xbox Series X|S x64-xbox-scarlett-static Builds static C++ libraries for Xbox Series X|S x64-xbox-xboxone Builds DLLs for Xbox One x64-xbox-xboxone-static Builds static C++ libraries for Xbox One   Another benefit of these new triplets is for open-source library maintainers, who can validate that their code will build against the WINAPI_FAMILY_GAMES partition used on Xbox using only the public Windows SDK. To learn more about the new triplets and how to use them, visit Chuck’s blog post on the topic.   Official vcpkg Tool Release Architecture is Now amd64 vcpkg tool releases on GitHub are now amd64 (was previously x86), as we do not expect many users to prefer x86 going forward. PR: Microsoft/vcpkg-tool#1005   Binary Caching Support for GitHub Actions Cache The vcpkg binary caching feature now works with the GitHub Actions Cache. GitHub Actions Cache allows you to use a REST API to query and manage the cache for repositories in GitHub Actions. PR: Microsoft/vcpkg-tool#836 (thanks @quyykk!)   vcpkg use now stacks with previous use or activate commands (but not vice versa) For artifacts users, we have made the behavior of vcpkg use and vcpkg activate consistent when used multiple times. You can run vcpkg use after previously running vcpkg use on another artifact to enable both artifacts at the same time. You can also run vcpkg use after a previous vcpkg activate to enable all artifacts invoked by […]

Read More

What’s New for CMake Tools 1.14 in VS Code – Test Explorer

The team has been working hard to provide new highly requested capabilities for CMake users. Now, in version 1.14, we have provided a new Test Explorer for using CTest with your CMake projects. This release also features open-source community contributions from users. Thanks for your contributions! Test Explorer One of our most highly-upvoted tickets in the CMake Tools Extension was the request for a Test Explorer for CTest. We are excited to announce that this is now available for users in the latest version of the CMake Tools extension in VS Code. Now, in your CMake projects, you can click the “Run CTest” icon along the bottom status bar or the “Testing” side panel icon to launch the test explorer. When the project is configured, the tests in your CMakeLists.txt will load in the Test Explorer. In the Test Explorer, you can view the detailed state of all your tests and the last results of these test runs. By clicking on the play button, you can run a specific test (or set of tests). Also, by clicking on the debug play button, you can debug these tests. Using the topmost icon, you can view the output of these tests. You can refresh these tests at any time using the refresh icon up top. We are continuing to listen to and work on all feedback we receive on the Test Explorer, so if you have any issues or suggestions, please report them in the Issues section of our GitHub repository. Future Work Next up, we are planning to experiment with the CMake tools user experience settings and implement CMake language services and a CMake Debugger. Is there anything else you’d like to see? Let us know! What do you think? Download the CMake Tools extension for Visual Studio Code and let us know what you think. We would love to see what you contribute to our repo and are active on reviews and collaboration. Comment below or reach us via email at visualcpp@microsoft.com or via Twitter at @VisualC.  

Read More

How Do I Program Fun Games?

Hello Everyone, C++ Builder Developers, and Delphi Developers, Last weeks, we started to release “Introduction to C++” series in our LearnCPlusPlus.org web site, we will continue to release basics of C++ in the next weeks.   If you are new a beginner, new to C++ or if you are a Delphi developer and want to learn or remember basics of C++, these posts are good to improve your programming skills. This is why we call everyone ! We keep adding new C++ blogs for C++ Builder, Dev-C++ and also most are compatible with other C++ compilers. We have another great new C++ Builder post picks from the last week.  If you are a beginner or want to jump into C++ Builder please visit our LearnCPlusPlus.org website for the great posts from basics to professional examples, full codes, snippets, etc.  Are you the next great games programmer? Do you want to develop a game like Minecraft without using 3D engines in C++ ? Want to develop a very simple text game ? We explain how to  develop a Guessing Game in C++. Dynamic Polymorphism and other very long words Do you want to learn structure of C++ programming language ? Do you want to learn how to use comments,  variables, Booleans.  Want learn Dynamic Polymorphism in C++ by the CppCon video? Discount până la 30% pentru C++ Builder RAD Studio C++ Builder is a great environment for learning to use C++ and is also powerful enough for all your development needs.  Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.Design. Code. Compile. Deploy.

Read More

Ultra-Fast Web Application Development using Delphi/C++ Builder

Choosing the Web framework for Web Application Development in Delphi or C++ Builder will no more a tough task for both developers and companies to meet the business needs. There is plenty of resources around Embercadero and the web about various frameworks with the pros and cons of each. Still, struggle to choose the right one for your need? Don’t worry this post will guide you through the available frameworks. RADStudio Included Server Technologies : Web Broker: Abstract the HTTP Server concept with concrete classes mapped to CGI, ISAPI, ApacheModules, Standalone(indy). It can maps URLs to actions, supports filters, and global handlers. To start with WebBroker Click here. DataSnap is a Delphi technology that allows the development of multi-tier applications, most notably multi-tier database applications. Supports Rest, TCP/IP, HTTP/HTTPS. Backward compatible with COM/DCOM. A serios of tutorials here. RAD Server Load Delphi and C++ business logic methods into RAD Server, add some users, and go. REST/JSON end-points are auto-created and managed. Access control is handled. Data storage is built-in or you can easily connect to any popular Enterprise RDBMS or cloud service.  SOAP Services: It’s a protocol which enables you to access remote data, or call remote procedures. SOAP data is transmitted using an XML wrapper, usually over an HTTP or direct TCP/IP. To create and use SOAP service Click here. RADStudio Included some Client Technologies for Web Application Development: Which includes Rest BaaS Client, Cloud Client libraries, Rest Client libraries, SOAP Clients. 3rd Party Web Frameworks: Client Focused: Pascal->JavaScript Transpilers. Write in Object Pascal and translate/Compiles in to JavaScript. Creates a pure Web client Solution. Compatible with many popular server solutions. TMSSoftware’s Web Core Integrates into Delphi IDE. Write object pascal and design in RAD Studio, builds pure HTML & JavaScript. Works with TMS’s cross-platform FNC components. Builds a Single Page Application. The large reusable component set with database access. Smart Mobile Studio (SMSC) transpiler has its own IDE uses familiar Object Pascal dialect. Compiles to pure JavaScript. Has lots of target like Node.js Tizen, console & Espruino. Has own RTL and full Visual component framework. ElevateSoft’s Web builder transpiler has its own IDE with components similar to VCL. Supports using native Elevate Web Builder Web server Modules. It compiles to optimized JavaScript. Full Stack or Client/Server Focused: Framework covers the Server app and client interface. Balanced Approach good to choose when Both Server and Visually designed UI is one project. WebBroker is the core on the server for most frameworks listed below. AtoZed Software’s IntraWeb: Installs into IDE, Modeled on VCL, Visual Client Designer. The client built from the JS and HTML library. Delphi UI event handlers run on servers, extensible via typescript. FMSoft UniGui: Installs into Delphi IDE, VCL like design and use. Provides data-aware controls, supports desktop and mobile. Allows optional javascript for client-side events and VCL like server event handlers. Open source Ethea Kitto2: Uses Web broker for the backend. No visual designer, make it easy to use Ext JS to build client. Server Focused Open Source: Delphi MVC Framework: Rest Server built on WebBroker includes Delphi IDE wizard. Runs under Apche or ISS on Windows & Linux. Restful RMM level 3 compliant. Synopse mORMot : Doesn’t use Web broker, Integrated SpiderMonkey JavaScript engine for server-side business logic. ORM/ODM: Object persistence on Almost any database (SQL or NoSQL).SOA: organize your business logic into REST services. Web MVC: Publish your ORM/SOA process as responsive Web applications. MArs Curiosity: Lightweight Rest Server built on WebBroker, installs into Delphi […]

Read More

The power of AI from Delphi and/or C++Builder

On the record of the webinar on “Using IBM Watson and the power of Artificial Intelligence (AI) from Delphi and/or C++Builder ” from Thursday, October 24, You can see the resources, slides, and code examples used in the webinar: Resources How to create a free IBM Cloud account:  https://ibm.biz/BdjLxy​ IBM Watson Tone Analyzer:  https://www.ibm.com/watson/services/tone-analyzer/​ IBM Watson Visual Recognition:  https://www.ibm.com/watson/services/visual-recognition/​ Delphi-JsonToDelphiClass by Petar Georgiev:  https://github.com/PKGeorgiev/Delphi-JsonToDelphiClass​ TNetHTTPClient:  http://docwiki.embarcadero.com/Libraries/Rio/en/System.Net.HttpClientComponent.TNetHTTPClient​ Al Mannarino Blog Posts:  https://community.idera.com/developer-tools/b/blog Slides IBMWatsonAI_Delphi_CBuilder.pdf Code Samples: Delphi:WatsonVisual.dproj IBMWatsonToneAnalyzer.dproj (WatsonToneAnalyzer.zip) NetHTTPClient.dproj (TNetHTTPClient.zip)  C++ Builder:   CppSystemNetHttpClient.cbproj On this webinar we showed: – How to leverage the power of machine learning from Delphi and/or C++Builder with the IBM Watson Artificial Intelligence (AI) Services.– This webinar covered using the IBM Watson REST API. IBM Watson is a collaborative environment with artificial Intelligence (AI) tools that you can use to collect and prepare training data, and to design, train, and deploy machine learning models.– On this webinar we specifically looked at two of the IBM Watson AI Services:– The Visual Recognition Service, and the– Tone Analysis Service (for Natural Language Classification), plus we will also look at– Watson Machine Learning.But before we dove into using Delphi and/or C++ Builder with the IBM Watson Artificial Intelligence (AI) REST Services, we took a quick refresher look at what’s possible with Delphi and/or C++ Builder for the integration with Web and/or REST Services. We had a quick review on how to integrate Delphi and/or C++ Builder with back-end services to provide access to data and enhance the Delphi and/or C++ Builder VCL and Multi-Device user experience!

Read More

C++17 On Windows 10 With The C++ Builder

As you know from C++ Builder 10.3, we have support for the modern C++17 On Windows 10 version. Here you can see the C++ 17 support chart. In this CodeRage session, Dion Mai shows demo applications in action. You can find out how you can use the new C++17 On Windows 10 functions and an updated C++17 standard library.  What you can find in this session? Moreover, you can find out how you can call WinRT functionalities. You can find all the wrappers from the RAD Studio installation folder. Source->RTL->Win->WinRT   C++ Builder provides three levels of development:1. Components (VCL and FMX)2. Common Libraries (RTL).3. Platform APIs (iOS, Android, Mac OS) In this post we will discuss the Common Libraries (RTL). C++ Builder has several hundred functions, macros, and classes that you call from within your C and C++ programs to perform a wide variety of tasks, including low- and high-level I/O, string and file manipulation, memory allocation, process control, data conversion, mathematical calculations, and more.​ The C++ Builder Run-Time Library (or RTL) is composed of a number of base header files that provide the underlying support for most of the VCL and FireMonkey component libraries . The RTL includes global routines, utility classes such as those that represent streams and lists, and classes such as TObject, TPersistent, and TComponent.​ Although closely allied with FireMonkey and VCL, the RTL does not include any of the components that appear on the Tool Palette. ​ Instead, the classes and routines in the RTL are used by the components that do appear on the Tool Palette, and are available for you to use in application code in either VCL projects or FireMonkey projects, or when you are writing your own classes.​ For example, the System header contains most of the Run-Time Library (RTL). ​ And from the System header, you have the System.Math.hpp header that defines classes, routines, types, variables, and constants related to mathematical operations, vectors and matrices.​ Or the System.Bluetooth.hpp header that provides classes to use the Bluetooth capabilities of the device that is running your application to connect to applications running on remote devices.​ Or the System.Sensors.hpp header that provides classes and components that let you obtain information and manage system sensors. The Sensors are pieces of hardware or software that can provide measures of physical quantities to your applications.​ Or the System.Threading.hpp header that defines classes and types that implement the parallel programming library.​

Read More