Note that there are some explanatory texts on larger screens.

plurals
  1. POHelp - please convert this LINQ example to C++
    primarykey
    data
    text
    <p>I'm putting together a presentation to show some of the productivity gains that I think C# may offer over C++. I've written some code in C# which I'd like to convert to C++. I don't have the time or up to date C++ to do the conversion justice, hence posting here.</p> <p>Code to convert:</p> <pre><code>using System.Collections.Generic; using System.Drawing; using System.Linq; namespace LinqTest { public class Vehicle { public int Id { get; set; } public Color Colour { get; set; } } public class Tyre { public int Id { get; set; } public int BikeId { get; set; } public int Size { get; set; } public string Brand { get; set; } } public class Car : Vehicle {} public class Bike : Vehicle {} public class Example { private readonly IList&lt;Car&gt; cars; private readonly IList&lt;Tyre&gt; bikeTyres; private readonly IList&lt;Bike&gt; bikes; public Example() { cars = new List&lt;Car&gt; { new Car {Id = 0, Colour = Color.Red}, new Car {Id = 1, Colour = Color.Blue}, new Car {Id = 2, Colour = Color.Green}, new Car {Id = 3, Colour = Color.Green} }; bikeTyres = new List&lt;Tyre&gt; { new Tyre {Id = 0, BikeId = 0, Brand = "TyreCo1", Size = 23}, new Tyre {Id = 1, BikeId = 0, Brand = "TyreCo1", Size = 23}, new Tyre {Id = 2, BikeId = 1, Brand = "TyreCo2", Size = 30}, new Tyre {Id = 3, BikeId = 1, Brand = "TyreCo2", Size = 30}, new Tyre {Id = 4, BikeId = 2, Brand = "TyreCo3", Size = 23}, new Tyre {Id = 5, BikeId = 2, Brand = "TyreCo3", Size = 23} }; bikes = new List&lt;Bike&gt; { new Bike {Id = 0, Colour = Color.Red}, new Bike {Id = 1, Colour = Color.Blue}, new Bike {Id = 2, Colour = Color.Green} }; } public IEnumerable&lt;Vehicle&gt; FindVehiclesByColour(Color colour) { var carVehicles = from car in cars where car.Colour == colour select car as Vehicle; var bikeVehicles = from bike in bikes where bike.Colour == colour select bike as Vehicle; return carVehicles.Union(bikeVehicles); } public IEnumerable&lt;Bike&gt; FindBikesByTyreSize(int size) { return (from bike in bikes join tyre in bikeTyres on bike.Id equals tyre.BikeId where tyre.Size == size select bike).Distinct(); } } } </code></pre> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload