mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Update images from snippet changes. (#4061)
Note, to see the results, here's a [README
link](https://github.com/carbon-language/carbon-lang/blob/654a06e0af7886dc43f52d35f4d11f32c5e8da9d/README.md)
(note this is for the 654a06e commit)
Enumerating changes:
- Finish the work started in #3735 by updating the images.
- Reverts changes to vector initialization style made in #3735, instead
preferring https://abseil.io/tips/88 style
- Switch array syntax to match [#syntax
discussion](https://discord.com/channels/655572317891461132/709488742942900284/1219410082719207444)
- Some nuanced highlighting changes to try matching what I'm seeing in
GitHub.
- The original intent was to match GitHub's highlighting, at least for
C++; Carbon highlighting is expected to be poor because it's not a
supported language.
This commit is contained in:
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 268 KiB After Width: | Height: | Size: 271 KiB |
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 277 KiB After Width: | Height: | Size: 313 KiB |
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 392 KiB After Width: | Height: | Size: 431 KiB |
@@ -67,7 +67,7 @@ void PrintTotalArea(std::span<Circle> circles) {
|
||||
}
|
||||
|
||||
auto main() -> int {
|
||||
std::vector<Circle> circles{{.r = 1.0}, {.r = 2.0}};
|
||||
std::vector<Circle> circles = {{.r = 1.0}, {.r = 2.0}};
|
||||
// Implicitly converts `vector` to `span`.
|
||||
PrintTotalArea(circles);
|
||||
return 0;
|
||||
@@ -85,7 +85,7 @@ class Circle {
|
||||
var r: f32;
|
||||
}
|
||||
|
||||
fn PrintTotalArea(circles: Slice(Circle)) {
|
||||
fn PrintTotalArea(circles: [Circle]) {
|
||||
var area: f32 = 0;
|
||||
for (c: Circle in circles) {
|
||||
area += Math.Pi * c.r * c.r;
|
||||
@@ -95,8 +95,8 @@ fn PrintTotalArea(circles: Slice(Circle)) {
|
||||
|
||||
fn Main() -> i32 {
|
||||
// A dynamically sized array, like `std::vector`.
|
||||
var circles: Array(Circle) = ({.r = 1.0}, {.r = 2.0});
|
||||
// Implicitly constructs `Slice` from `Array`.
|
||||
var circles: array [Circle] = ({.r = 1.0}, {.r = 2.0});
|
||||
// Implicitly constructs a slice from the array.
|
||||
PrintTotalArea(circles);
|
||||
return 0;
|
||||
}
|
||||
@@ -107,6 +107,7 @@ fn Main() -> i32 {
|
||||
```cpp
|
||||
// C++ code used in both Carbon and C++:
|
||||
#include <stdfloat>
|
||||
|
||||
struct Circle {
|
||||
std::float32_t r;
|
||||
};
|
||||
@@ -116,7 +117,7 @@ package Geometry;
|
||||
import Cpp library "circle.h";
|
||||
import Math;
|
||||
|
||||
fn PrintTotalArea(circles: Slice(Cpp.Circle)) {
|
||||
fn PrintTotalArea(circles: [Cpp.Circle]) {
|
||||
var area: f32 = 0;
|
||||
for (c: Cpp.Circle in circles) {
|
||||
area += Math.Pi * c.r * c.r;
|
||||
@@ -131,8 +132,8 @@ fn PrintTotalArea(circles: Slice(Cpp.Circle)) {
|
||||
|
||||
auto main() -> int {
|
||||
std::vector<Circle> circles = {{1.0}, {2.0}};
|
||||
// Carbon's `Slice` supports implicit construction from `std::vector`,
|
||||
// similar to `std::span`.
|
||||
// A Carbon slice supports implicit construction
|
||||
// from `std::vector`, similar to `std::span`.
|
||||
Geometry::PrintTotalArea(circles);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user