Archive for the ‘C++’ Category

What Happened in Frankfurt?

August 6, 2009

Concepts have been removed from C++0X. I’ve written a description of what happened and how we got to this point over at a new C++-related blog, C++Next. Enjoy!

With that, I am also closing down the ConceptGCC blog. Now that I am working on a new, open-source C++ compiler, I am not involved in the development of GCC (or ConceptGCC), it no longer makes sense to keep this blog going.  Any future C++- and concepts-related posts will appear over at C++Next.

Concepts are in C++0x!

September 25, 2008

Last Saturday in San Francisco, the ISO C++ committee voted to accept the concepts proposals into the upcoming Candidate Draft (CD) for C++0x. In all, thirteen proposals related to concepts were voted into the CD, covering the core language, foundational concepts, iterators, containers, algorithms, and more. In the next few weeks, the CD should be available for comments, as will the final versions of each of the proposals.

I think that now is a good time to point out and thank those who have invested significant effort in getting concepts to this point. On the language side, James Widman authored a large portion of the concepts wording, and the standardese is in much, much better shape because of his involvement. John Spicer provided extremely detailed feedback on the concepts wording and helped shape the formulation of concepts. The concepts design comes from work by Gabriel Dos Reis, Ronald Garcia, Jaakko Jarvi, Andrew Lumsdaine, Jeremy Siek, Bjarne Stroustrup, and Jeremiah Willcock.

On the library side, Mat Marcus shepherded the library concepts proposals through the Library Working Group, and authored, reviewed, and improved various parts of the conceptualized standard library. Daniel Kruegler provided extremely detailed review of and corrections to essentially every concepts proposal, and authored parts of the conceptualized standard library. Walter Brown, Pablo Halpern, and Alisdair Meredith all provided detailed reviews of and improvements to the library concepts proposals, including authoring several library concepts proposals of their own.

Many others have shaped the final form of concepts, including  David Abrahams, J. Stephen Adamczyk, Matthew Austern, Alberto Ganesh Barbati, Howard Hinnant, Mat Marcus, Alisdair Meredith, David Musser, Sean Parent, Sibylle Schupp, Alexander Stepanov, Alan Talbot, Thomas Witt, and Marcin Zalewski.

Thank you to everyone who has been involved thus far in concepts, but you’re not off the hook yet: there are yet more wording bugs to find, libraries to conceptualize, and dark corners to find.

Introduction to Concepts Article at DevX

August 25, 2008

DevX has a special report on C++0x, which includes an introductory article about concepts:

  http://www.devx.com/SpecialReports/Article/38864

In other concepts news: work on getting concepts into the C++0x standard is still ongoing. With more than 400 pages of specification currently under consideration as part of the concepts proposal, the volume of changes has slowed progress. However, I’m hoping for success at the upcoming C++ committee meeting in San Francisco this September.

ConceptGCC — BoostCon Edition is now available

May 10, 2007

BoostCon 2007 is coming up next week, and will be full of interesting sessions on Boost and C++0x. I’ll be giving a half-day tutorial on concepts, and have rolled a special version of ConceptGCC just for this occasion (and, to fix a critical bug or two that affects my slides). The BoostCon edition of ConceptGCC contains the following improvements:

  • The range-based for loop now deals with temporary containers appropriately.
  • Rvalue-reference arguments in associated functions now forward as an rvalue.
  • The iterator concepts have been simplified and expanded in scope, providing better support for proxies; vector<bool>::iterator is again a RandomAccessIterator.
  • Added Semiregular and Regular concepts.
  • Added support for delegating constructors (for real this time).
  • Added the DerivedFrom concept.

The DerivedFrom concept

May 8, 2007

We recently decided that we needed a new concept, DerivedFrom, to express the requirement for an inheritance relationship between two types. This concept has the following definition:

  concept DerivedFrom<typename Derived, typename Base> { /*unspecified*/ }

DerivedFrom is a compiler-support concept, like SameType. We expect that most of its uses will be to intermingle the object-oriented and generic programming facilities of C++0x, e.g.,

  template<typename T>
  requires DerivedFrom<T, Shape>
  void draw(T& shape) {
    // Can use Shape's member functions via "shape" object.
  }

DerivedFrom is now supported (albeit “lightly tested”) in the development version of ConceptGCC.

Requirement Propagation and CopyConstructible

May 3, 2007

The concepts proposal contains a feature called “requirement
propagation” (formerly referred to as “constraint propagation”), which
implicitly defines constraints based on the declaration of a
template. If you didn’t know that requirement propagation existed,
don’t worry; it’s a behind-the-scenes feature that reduces the size of
requirements clauses.

There is one aspect of requirement propagation that we would like to
change. As of N2193, [temp.req.prop] paragraph 2 says:

For every type T that appears as an argument or return type in a
function declarator, the requirement std::MoveConstructible<T> is
implicitly added to the requirements clause. [ Example:

    template<EqualityComparable T>
    bool eq(T x, T y); // implicitly adds requirement CopyConstructible<T>

--end example ]

For various reasons, this feature is problematic and has been removed from ConceptGCC. This change will break some “existing” concepts code. For example, the function “negate” below is currently (according to N2193) well-formed:

  auto concept Negatable<typename T> {
    T operator-(T);
  }

  template<Negatable T>
  T negate(const T& x) { return -x; }

ConceptGCC used to compile this. With today’s development version of ConceptGCC, however, we get an error message:

  beep.C: In function 'T negate(const T&)':
  beep.C:6: error: constructor 'T::T(const T&)' is inaccessible

To remedy the error, add a CopyConstructible requirement, so that “negate” can return its value. Formerly, the
compiler would have added this requirement:

  template<Negatable T> requires CopyConstructible<T>
  T negate(const T& x) { return -x; }

Wanted: Doxygen Hacker

April 24, 2007

Doxygen is a great tool for turning C++ code and comments into reference documentation. We would absolutely love to use Doxygen in the ConceptGCC standard library, and in other libraries that are using Concepts in C++, but there’s one big snag: Doxygen doesn’t parse concepts, or requirements clauses, or any of the new constructs introduced into C++0x.

We’re looking for someone willing to implement C++0x support into Doxygen, so that we can produce great reference documentation automatically for ConceptC++ code. Having this functionality would be a huge benefit for C++0x and concepts. Any takers?

Variadic Templates are in C++0x

April 24, 2007

Variadic templates have now been accepted into C++0x and will be in the next C++0x working paper. Variadic templates have the distinction of being the only C++0x feature that has made it completely through the Core Working Group and into the working paper within a single committee meeting.

Variadic templates are implemented in ConceptGCC alpha 6 and in the experimental C++0x mode in GCC 4.3.

ConceptGCC 4.3.0 Alpha 6 is now available

April 11, 2007

ConceptGCC is a prototype implementation of the Concepts language
feature for C++0x, which offers improved type-checking for C++
templates and complete support for the Generic Programming paradigm.

ConceptGCC 4.3.0 alpha 6 provides many improvements over previous
versions of ConceptGCC, including support for the concept syntax introduced by the
latest concepts proposal, N2193, along with support for many other
C++0x features, such as:
– Rvalue references
– Right angle brackets
– Default template arguments for function templates
– Delegating constructors
– decltype
– Static assertions
– C99 preprocessor
– Variadic templates
– Range-based for loop

Source code and pre-compiled binaries for various platforms are
available on the ConceptGCC download page at:

http://www.generic-programming.org/software/ConceptGCC/download.php

For more information about concepts, please see:

http://www.generic-programming.org/languages/conceptcpp/

Concepts at ACCU and BoostCon

April 5, 2007

There are two upcoming concepts tutorials where you can learn all about concepts and how they fit into C++.

The first will be a 90-minute tutorial at ACCU 2007, on April 14th in Oxford, UK. This tutorial will cover all of the basics of writing concepts, using concepts to constrain templates, and writing concept maps.

The second will be a half-day, hands-on tutorial at BoostCon 2007. We’ll start from the concept basics, and build a miniature STL-like library from the ground up using concepts. BoostCon will also have a second, more advanced tutorial on taking an existing C++ template library and evolving it to use concepts, with particular focus on making the library work both with and without concepts. Early registration is open for just four more days. Come join in the fun!