NuGet has recently added support for native projects. This simplifies a lot deployment of native libraries. Even though cpplinq is not a big library (in fact is just a header file) I have created a NuGet package so that you are able to automatically add it to your project.

Here is what you have to do.

  1. Make sure you have NuGet 2.5 or newer, otherwise the NuGet package manager won’t show up in your VC++ projects.
  2. In the context menu for your project choose Manage NuGet Packages…
  3. Search for cpplinq and install the package.
  4. Include the cpplinq.hpp header and start using the library. Here is a sample to test that everything is all right.

Notice that all the settings for library (such as adding the proper entry for the include directories or defining NOMINMAX so that min and max macros will not be defined for the project) are automatically performed, so you can focus on coding.

, , , , , , , Hits for this post: 50143 .

cpplinq new operators

There are some new operators available in cpplinq: singleton, generate, pairwise and zip_with.

This operator create a range with a single element, specified as argument. Using the operator is straight forward.

This operator creates a range using a given predicate.

Generates a new range of pairs by grouping adjacent elements of an input range. On an empty range it yields an empty range.

Generates a new range of pairs by grouping together elements from two different ranges. If the two input ranges have different sizes, the result has the size of the smallest range. If any of the input ranges is empty, the result is an empty range.

, , , , Hits for this post: 27942 .

Microsoft has announced that Visual Studio 2012 Update 2 will bring support in Visual Studio and TFS for git. They already used git on codeplex and this move shows how popular git has become. I don’t work much with git, but as I said codeplex uses git, and I used it for working on cpplinq. However, the experience with Git Source Control Provider extension for Visual Studio was not the most pleasant. Fortunately, Visual Studio Tools for Git is a different story, allowing you to work exclusively from Visual Studio, without the need of addition tools. After giving it a try, I must say that even if it’s in CTP and still has some issues, it’s a totally different story than the previous extension or external tools I used. However, support for git will not be added to the previous versions of Visual Studio.

Here is more about the support for git:

Before you can start working with git, you need two things:

  1. Visual Studio 2012 Update 2 CTP 2
  2. Visual Studio Tools for Git

Extensions manager

In this post I’ll show what it takes to clone a git repository, work on the project, commit and push the changes on the remote branch.

To clone a repository you have go to Connect to Team Projects in Team Explorer, and under Local Git Repositories use the Clone pane to enter the URL of the server repository and the local destination. After the repository has been cloned, it shows up in the list, as shown below.

Cone a git

You can change the settings, such as your credentials from the Settings pane.

Git settings

To view your changes you can use the Git Changes > Commits pane. You can see included and excluded changes, and also untracked files. To commit your changes, provide a description (mandatory) and hit the Commit button. The page updates after the commit finishes.

Committing changes

It is possible to view the changes on each file with the built-in tools:

source file diff

After you committed all your changes and you’re ready to publish them on the server you can push the ongoing commits. If there are changes on the server, you must first pull those changes, merge locally, commit again and then push.

push ongoing commits

You can view the history for an entire branch from Team Explorer > Git Changes > Branches

Branch history

or for a single file from Solution Explorer (it is also possible to compare two versions).

File history

, , , Hits for this post: 40783 .

2012 in Review

Here is an overview of the things that I’ve done in 2012.

Codexpert Revamped
The main site for the Romanian C++ community has a brand new, modern look (all built with HTML5), making things easier to find. We also now feature a blog in English, which is intended to replace the old article section.
codexpert blog

cpplinq library
cpplinq is an open-source template library that provides LINQ-like operators for querying collections (arrays and STL containers) in C++11. The project was initiated by Mårten Rånge, and is available on codeplex. Here is a sample:

cpplinq documentation
cpplinq – LINQ Query Operators for C++ Sequences
cpplinq: An introduction
cpplinq: range generators and conversion operators
cpplinq: set operators

What’s New in VS11 for Native Development
Authoring Documentation with DocProject and Sandcastle
Loading Assemblies from Anywhere into a New AppDomain
A C++ SHA1 and MD5 Implementation with CryptoAPI
cpplinq – LINQ Query Operators for C++ Sequences – CodeProject Best C++ article of November
10 More Visual Studio Debugging Tips for Native Development – CodeProject Best C++ article of October
10 Even More Visual Studio Debugging Tips for Native Development

Keyboard input and TAB navigation between WPF controls in a Win32 application
How to Determine What Process Loaded a DLL
T4 Lessons Learned
A tale of two flags: DS_CONTROL and WS_EX_CONTROLPARENT
Sorting a CTreeCtrl
Missing 64-bit compiler and tools
DocProject Tips and Tricks
A Quick Look at Visual Studio 11 Beta

My Alchemy for Windows game has reached 555 elements and is available in 18 languages. It has been downloaded so far for more than 45,000 times, which greatly exceeded my expectations.

, , , , , Hits for this post: 25002 .

cpplinq: set operators

In the previous posts I introduced cpplinq, a C++ template library that provides .NET-like query operators for sequences of objects in C++11. In this third installment I will discuss the set operators the library provides.

There are four set operators: distinct, union_with (called so because union is a keyword in C++), intersect_with (suffix _with is for consistency with the union operator) and except. These operators should be pretty straight forward: distinct eliminates the duplicate elements from a sequence, yielding a new sequence with only the distinct elements (in the order their original order), union_with produces the set union of two sequences, intersect_with produces the set intersection of two sequences and except produces the set difference of two sequences.

Before seeing some examples, it worth nothing that all these operators delay the traversal of the sequences until the resulting object is enumerated.

Let’s see some examples:

You can learn more about these operators (and the others that are implemented) by reading the cpplinq query operators documentation.

, , , , , Hits for this post: 36027 .

In my previous post I introduced cpplinq, a C++ template library that provides .NET-like query operators for sequences of objects in C++11. In this second installment I will discuss about two things: range generators and range conversion operators. These two sets of operators are ubiquitous in queries.

Range generators

A range generator builds an object that represents the range on which query operators are applied. The library provides several such generators:

  • from_iterators: constructs a range from a pair of iterators
  • from: constructs a range from an STL-like container that provides begin() and end() methods (representing the first and past-the-end elements). This is basically a wrapper on from_iterators operator.

    This is similar to:
  • from_array: constructs a range from an array.

    This is similar to:

In addition to the “from” operators, the library also provides several .NET like range generators:

  • range: generates a range of integral, consecutive numbers, starting with an initial seed and having a specified number of elements.
  • repeat: generates a range by repeating a value a given number of times
  • empty: returns an empty range of a given type

Range conversion operators

A conversion operator folds a range into a container that holds the values of the range. There are several such conversion operators that the library provides.

  • to_vector: creates a std::vector<TValue> from a range, where TValue is the type of the elements of the range.
  • to_list: creates a std::list<TValue> from a range, where TValue is the type of the elements of the range.
  • to_map: creates a std::map<TKey, TValue> from a range. It takes a predicate that selects the value to use as the key for each element of the range. It implements a one-to-one dictionary that maps keys to single values.
  • to_lookup: creates a cpplinq::lookup<TKey, TElement> from a sequence. It implements a one-to-many dictionary that maps keys to sequences of values.

, , , , , , , Hits for this post: 34526 .

cpplinq: An introduction

cpplinq is a C++ template library that provides .NET-like query operators for sequences of objects in C++11. cpplinq is an open-source library that works both with VC++ compilers (2010 and 2012) and gcc (4.7.0 is the version used for unit tests). The library supports most of the .NET query operators and is extendable with additional operators that can suite some particular use. If you’re not familiar with .NET query operators, this article,, lists and explain them.

The light-weighted library consists of a series of template classes and helper methods, provided in a single header under the namespace cpplinq.

This is a short introduction to the library. More posts will follow. Let’s see some examples.

The following code retrieves all the prime numbers from an array.

A slightly variation produces a sequence of first N prime numbers and transforms them into strings.

The next sample retrieves all the orders from a customer.

Callinq print_orders_by_cust() with argument 1 would print:

On the other hand, if you want to print the last order from a particular customer, the function above would change to something like this:

Calling print_last_order_for_customer() with argument 1 would print:

Hopefully this provides a quick view over the capabilities of the library. In following posts I will show more examples and discuss some of the query operators. To learn more about the library see the following articles:

, , , , , Hits for this post: 42786 .