Defining Interfaces in C++ with ‘Concepts’ (C++20) -- Daniel Lemire

In an earlier blog post, I showed that the Go programming language allows you to write generic functions once you have defined an interface.

Defining Interfaces in C++ with ‘Concepts’ (C++20)

by Daniel Lemire

From the article:

Java has a very similar concept under the same name (interface). I gave the following example:


	type IntIterable interface {

	    HasNext() bool

	    Next() uint32

	    Reset()

	}

	

	func Count(i IntIterable) (count int) {

	    count = 0

	    i.Reset()

	    for i.HasNext() {

	        i.Next()

	        count++

	    }

	    return

	}

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.