Nish's technology blog

Direct WordPress URL

VC++ 2015 – Lazy generators

If you have ever used iterators in C# or Visual Basic, then this is essentially the same thing. You would need to enable the new experimental /await compiler option, same as in the previous blog entry. Calling this method would be fairly straightforward. And here’s the expected output. I added the console output to demonstrate … <a href="" class="more-link">Continue reading <span class="screen-reader-text">VC++ 2015 – Lazy generators</span></a>

VC++ 2015 – Using resumable functions

Visual C++ 2015 has a new compiler option called /await that can be used to write and call resumable functions. Do note that this is an experimental feature and even the associated headers are in an experimental sub-directory. There is no UI option to turn this compiler option in VS 2015, so you would need … <a href="" class="more-link">Continue reading <span class="screen-reader-text">VC++ 2015 – Using resumable functions</span></a>

VS14 CTP – Implement Pure Virtuals

This refactoring option implements stub-functions for all pure virtuals in one or all base classes. Here’s an example. If you right click on a specific base class, you’ll get an option to just implement pure virtuals for that class. If you right click on the derived class name, you’ll get the option to implement all … <a href="" class="more-link">Continue reading <span class="screen-reader-text">VS14 CTP – Implement Pure Virtuals</span></a>

VS14 CTP – Move Definition Location

The CTP adds a refactoring option to move a function definition from header to cpp, or vice-versa. Just right-click on the definition, choose Refactor/Move Definition Location and that’s it. Now your code looks like this. You can do the reverse too. There seems to be a bug in this CTP though – when you move … <a href="" class="more-link">Continue reading <span class="screen-reader-text">VS14 CTP – Move Definition Location</span></a>

VS14 CTP – Create Declaration / Definition

The CTP 2 has a mostly stable implementation of the “Create Declaration / Definition” refactoring tool for your C++ projects. It lets you auto generate the definition or declaration of a member function. Example, if you have a class called Employee, declared in Employee.h and defined in Employee.cpp, you can type in a function declaration … <a href="" class="more-link">Continue reading <span class="screen-reader-text">VS14 CTP – Create Declaration / Definition</span></a>

VS14 CTP – User-defined literals

User-defined literals is a C++ 11 feature that’s been implemented in the VS 14 CTP. Some of the standard headers have already been updated to define user defined literals. Example, <string> has an s-suffix for string literals. So you can do the following now, and both lines of code are identical. The definition in <string> … <a href="" class="more-link">Continue reading <span class="screen-reader-text">VS14 CTP – User-defined literals</span></a>

VS14 CTP – auto return type

Instead of implementing all the C++ 11 features first and then targeting C++ 14, the VC++ team have taken an approach where they will implement both in parallel. This will allow them to implement popular C++ 14 features ahead of less popular C++ 11 features. Either way, at some point, they will have a release … <a href="" class="more-link">Continue reading <span class="screen-reader-text">VS14 CTP – auto return type</span></a>

VS14 CTP – Inheriting constructors

Inheriting constructors is a C++ 11 feature implemented in this CTP. It extends the using declaration to allow a derived class to indicate that it needs to inherit the base class constructors. Here’s a basic example. You’ll get this error message (as of this CTP). Had Base had a default constructor or if the existing … <a href="" class="more-link">Continue reading <span class="screen-reader-text">VS14 CTP – Inheriting constructors</span></a>

VS14 CTP – Extended sizeof

The Visual Studio 14 CTP is now available as a VM on Azure. The C++ compiler in the CTP has several enhancements for C++ 11 and C++ 14 features. C++ 11 proposes a feature to extend sizeof to apply to non-static data members without needing a temporary object. The CTP implements that feature. Consider the … <a href="" class="more-link">Continue reading <span class="screen-reader-text">VS14 CTP – Extended sizeof</span></a>

Azure queues – updating messages

The default invisibility timeout of 30 seconds may not suffice on occasions. For those situations, you can change the timeout so that you get more time to do something with your message prior to deleting it. You can also update an existing message. The code snippet below shows how that can be done. One thing … <a href="" class="more-link">Continue reading <span class="screen-reader-text">Azure queues – updating messages</span></a>

Using Azure queues from C++

Azure queues are used to store a large number of items (referred to as messages). Each message can go up to 64 Kb. A typical use for queues is intra-app communication, for example your website might add messages to the queue for a background service to process later on. The C++ Azure storage SDK maintains … <a href="" class="more-link">Continue reading <span class="screen-reader-text">Using Azure queues from C++</span></a>

Downloading blob content

I missed this in the previous blog entry. The SDK makes it really trivial to extract blob data. For text content you can directly get the text, and for non-text content you can either download to a file or to a stream. The code snippet below shows how it’s done.

Using Azure blob storage from C++

Blob storage is for storing large amounts of semi-structured or unstructured data such as images, videos, documents etc. The blob service lets you create named containers that can then contain one or more named blobs which can be publicly (optional) accessed via an URI. Creating blobs The classes/methods used are very similar to that used … <a href="" class="more-link">Continue reading <span class="screen-reader-text">Using Azure blob storage from C++</span></a>

Writing custom queries against an Azure table

While not as powerful as SQL, Azure tables do allow you to do minimal querying. With the native SDK, you’d do this using the table_query object’s set_filter_string function. Here’s a modified ReadTableData method from the previous blog entries. Here’s an example query that gets all rows within a range of RowKey values. The combine_filter_conditions function … <a href="" class="more-link">Continue reading <span class="screen-reader-text">Writing custom queries against an Azure table</span></a>

Modifying Azure table data

The last blog entry showed how to read data from Azure storage tables. This blog entry will show how to insert, update, and delete data to and from Azure table storage. Inserting data Azure table data is really just about properties. So what’s involved is creating a new table entity, setting up some properties (named … <a href="" class="more-link">Continue reading <span class="screen-reader-text">Modifying Azure table data</span></a>

Azure Storage access using C++

The Microsoft Azure Storage Client Library for C++ is a library built on top of the C++ REST SDK that lets you access Azure Storage from your C++ apps. You need to install it via NuGet. While installing it, I could not locate it using the NuGet packages UI in Visual Studio 2013. Instead I … <a href="" class="more-link">Continue reading <span class="screen-reader-text">Azure Storage access using C++</span></a>

Using weak_ptr

The weak_ptr holds a weakly referenced pointer to an object that is managed by a shared_ptr (or by multiple shared_ptr instances). The weak_ptr does not affect the strong ref count. You typically construct a weak_ptr out of a shared_ptr, and then when you need to access the underlying object, you call lock() on the weak_ptr … <a href="" class="more-link">Continue reading <span class="screen-reader-text">Using weak_ptr</span></a>

Using shared_ptr

While unique_ptr is meant for single-owner scenarios, shared_ptr is the reference counted smart pointer class that allows you to share the smart pointer around your code. Consider the code snippet below, which uses the NumberStore example from the previous blog entry. The output will be: The ref count goes up inside Foo‘s body as Foo … <a href="" class="more-link">Continue reading <span class="screen-reader-text">Using shared_ptr</span></a>

Using unique_ptr instead of auto_ptr

I’ve had a bit of a blogging hiatus and hope to make amends for that. Going forward, I will continue to blog on modern C++ features and also focus on newer frameworks from Microsoft (primarily C++ focused, but non-C++ technologies that interest me will also be discussed). For years, we’ve all used auto_ptr with all … <a href="" class="more-link">Continue reading <span class="screen-reader-text">Using unique_ptr instead of auto_ptr</span></a>

VC++ 2013 – Initializer lists and uniform initialization

We’ve always been able to use initializer lists with arrays, now you can do it with any type that has a method that takes an argument of type std::initializer_list<T> (including constructors). The standard library collections have all been updated to support initializer lists. And it’s trivial to do this with your own functions. You can … <a href="" class="more-link">Continue reading <span class="screen-reader-text">VC++ 2013 – Initializer lists and uniform initialization</span></a>