Upgrade WPILib and upgraded compilers to C++17

I haven't touched the CTRE libraries yet, although they may need to be
upgraded as well.

Note that this change makes it so that you need either Ubuntu 18.04 or
later or debian buster or later in order to build the code (you may be
able to build code for the roborio on older operating systems, but
running the tests will not work normally).

Change-Id: I0cfa37fe37f830edde6d305e1f50414c369098e4
diff --git a/y2019/jevois/BUILD b/y2019/jevois/BUILD
index 0363ced..dc170be 100644
--- a/y2019/jevois/BUILD
+++ b/y2019/jevois/BUILD
@@ -98,7 +98,6 @@
         "//aos/logging",
         "//aos/util:bitpacking",
         "//third_party/GSL",
-        "//third_party/optional",
     ],
 )
 
@@ -116,7 +115,6 @@
         ":structures_mcu",
         "//aos/util:bitpacking",
         "//third_party/GSL",
-        "//third_party/optional",
     ],
 )
 
@@ -137,7 +135,6 @@
         "//aos/logging",
         "//aos/util:bitpacking",
         "//third_party/GSL",
-        "//third_party/optional",
     ],
 )
 
@@ -157,7 +154,6 @@
         "//aos/containers:sized_array",
         "//aos/util:bitpacking",
         "//third_party/GSL",
-        "//third_party/optional",
     ],
 )
 
diff --git a/y2019/jevois/spi.cc b/y2019/jevois/spi.cc
index b6a281e..5c504e2 100644
--- a/y2019/jevois/spi.cc
+++ b/y2019/jevois/spi.cc
@@ -183,7 +183,7 @@
   return transfer;
 }
 
-tl::optional<TeensyToRoborio> SpiUnpackToRoborio(
+std::optional<TeensyToRoborio> SpiUnpackToRoborio(
     gsl::span<const char, spi_transfer_size()> transfer) {
   TeensyToRoborio message;
   gsl::span<const char> remaining_input = transfer;
@@ -232,7 +232,7 @@
     remaining_input = remaining_input.subspan(sizeof(received_crc));
     AOS_CHECK(remaining_input.empty());
     if (calculated_crc != received_crc) {
-      return tl::nullopt;
+      return std::nullopt;
     }
   }
   return message;
@@ -267,7 +267,7 @@
   return transfer;
 }
 
-tl::optional<RoborioToTeensy> SpiUnpackToTeensy(
+std::optional<RoborioToTeensy> SpiUnpackToTeensy(
     gsl::span<const char, spi_transfer_size()> transfer) {
   RoborioToTeensy message;
   gsl::span<const char> remaining_input = transfer;
@@ -298,7 +298,7 @@
     memcpy(&received_crc, &remaining_input[0], sizeof(received_crc));
     remaining_input = remaining_input.subspan(sizeof(received_crc));
     if (calculated_crc != received_crc) {
-      return tl::nullopt;
+      return std::nullopt;
     }
   }
   return message;
diff --git a/y2019/jevois/spi.h b/y2019/jevois/spi.h
index 7c14a57..8b16d5c 100644
--- a/y2019/jevois/spi.h
+++ b/y2019/jevois/spi.h
@@ -6,7 +6,7 @@
 #include <array>
 
 #include "third_party/GSL/include/gsl/gsl"
-#include "third_party/optional/tl/optional.hpp"
+#include <optional>
 #include "y2019/jevois/structures.h"
 
 // This file manages serializing and deserializing the various structures for
@@ -27,10 +27,10 @@
 using SpiTransfer = std::array<char, spi_transfer_size()>;
 
 SpiTransfer SpiPackToRoborio(const TeensyToRoborio &message);
-tl::optional<TeensyToRoborio> SpiUnpackToRoborio(
+std::optional<TeensyToRoborio> SpiUnpackToRoborio(
     gsl::span<const char, spi_transfer_size()> transfer);
 SpiTransfer SpiPackToTeensy(const RoborioToTeensy &message);
-tl::optional<RoborioToTeensy> SpiUnpackToTeensy(
+std::optional<RoborioToTeensy> SpiUnpackToTeensy(
     gsl::span<const char, spi_transfer_size()> transfer);
 
 }  // namespace jevois
diff --git a/y2019/jevois/teensy.cc b/y2019/jevois/teensy.cc
index 58d1570..4da89a8 100644
--- a/y2019/jevois/teensy.cc
+++ b/y2019/jevois/teensy.cc
@@ -1,6 +1,8 @@
 #include <inttypes.h>
 #include <stdio.h>
 
+#include <optional>
+
 #include "aos/time/time.h"
 #include "motors/core/kinetis.h"
 #include "motors/core/time.h"
@@ -115,18 +117,18 @@
   SpiQueue(const SpiQueue &) = delete;
   SpiQueue &operator=(const SpiQueue &) = delete;
 
-  tl::optional<gsl::span<const char, spi_transfer_size()>> Tick() {
+  std::optional<gsl::span<const char, spi_transfer_size()>> Tick() {
     {
       DisableInterrupts disable_interrupts;
       if (waiting_for_enable_ || waiting_for_disable_) {
-        return tl::nullopt;
+        return std::nullopt;
       }
     }
     const auto now = aos::monotonic_clock::now();
     if (TransferTimedOut(now)) {
       printf("SPI timeout with %d left\n", static_cast<int>(to_receive_.size()));
       WaitForNextTransfer();
-      return tl::nullopt;
+      return std::nullopt;
     }
     {
       DisableInterrupts disable_interrupts;
@@ -138,7 +140,7 @@
     if (DeassertHappened(now)) {
       printf("CS deasserted with %d left\n", static_cast<int>(to_receive_.size()));
       WaitForNextTransfer();
-      return tl::nullopt;
+      return std::nullopt;
     }
     bool all_done;
     {
@@ -160,7 +162,7 @@
       WaitForNextTransfer();
       return received_transfer_;
     }
-    return tl::nullopt;
+    return std::nullopt;
   }
 
   void HandleInterrupt() {
diff --git a/y2019/jevois/uart.cc b/y2019/jevois/uart.cc
index 6ebfe30..b1fdcfb 100644
--- a/y2019/jevois/uart.cc
+++ b/y2019/jevois/uart.cc
@@ -55,12 +55,13 @@
   return result;
 }
 
-tl::optional<CameraFrame> UartUnpackToTeensy(gsl::span<const char> encoded_buffer) {
+std::optional<CameraFrame> UartUnpackToTeensy(
+    gsl::span<const char> encoded_buffer) {
   std::array<char, uart_to_teensy_size()> buffer;
   if (static_cast<size_t>(
           CobsDecode<uart_to_teensy_size()>(encoded_buffer, &buffer).size()) !=
       buffer.size()) {
-    return tl::nullopt;
+    return std::nullopt;
   }
 
   CameraFrame message;
@@ -97,7 +98,7 @@
     remaining_input = remaining_input.subspan(sizeof(received_crc));
     AOS_CHECK(remaining_input.empty());
     if (calculated_crc != received_crc) {
-      return tl::nullopt;
+      return std::nullopt;
     }
   }
   return message;
@@ -142,13 +143,13 @@
   return result;
 }
 
-tl::optional<CameraCalibration> UartUnpackToCamera(
+std::optional<CameraCalibration> UartUnpackToCamera(
     gsl::span<const char> encoded_buffer) {
   std::array<char, uart_to_camera_size()> buffer;
   if (static_cast<size_t>(
           CobsDecode<uart_to_camera_size()>(encoded_buffer, &buffer).size()) !=
       buffer.size()) {
-    return tl::nullopt;
+    return std::nullopt;
   }
 
   CameraCalibration message;
@@ -187,7 +188,7 @@
     remaining_input = remaining_input.subspan(sizeof(received_crc));
     AOS_CHECK(remaining_input.empty());
     if (calculated_crc != received_crc) {
-      return tl::nullopt;
+      return std::nullopt;
     }
   }
   return message;
diff --git a/y2019/jevois/uart.h b/y2019/jevois/uart.h
index b9e784b..14a46da 100644
--- a/y2019/jevois/uart.h
+++ b/y2019/jevois/uart.h
@@ -3,7 +3,7 @@
 
 #include "aos/containers/sized_array.h"
 #include "third_party/GSL/include/gsl/gsl"
-#include "third_party/optional/tl/optional.hpp"
+#include <optional>
 #include "y2019/jevois/cobs.h"
 #include "y2019/jevois/structures.h"
 
@@ -30,10 +30,10 @@
     aos::SizedArray<char, CobsMaxEncodedSize(uart_to_camera_size())>;
 
 UartToTeensyBuffer UartPackToTeensy(const CameraFrame &message);
-tl::optional<CameraFrame> UartUnpackToTeensy(gsl::span<const char> buffer);
+std::optional<CameraFrame> UartUnpackToTeensy(gsl::span<const char> buffer);
 
 UartToCameraBuffer UartPackToCamera(const CameraCalibration &message);
-tl::optional<CameraCalibration> UartUnpackToCamera(
+std::optional<CameraCalibration> UartUnpackToCamera(
     gsl::span<const char> buffer);
 
 }  // namespace jevois
diff --git a/y2019/jevois/uart_test.cc b/y2019/jevois/uart_test.cc
index b8f25c1..4f58e73 100644
--- a/y2019/jevois/uart_test.cc
+++ b/y2019/jevois/uart_test.cc
@@ -93,7 +93,7 @@
   }
   {
     UartToTeensyBuffer buffer = UartPackToTeensy(input_message);
-    buffer[0] = 255;
+    buffer[0] = -1;
     EXPECT_FALSE(UartUnpackToTeensy(buffer));
   }
 }
@@ -118,7 +118,7 @@
   }
   {
     UartToCameraBuffer buffer = UartPackToCamera(input_message);
-    buffer[0] = 255;
+    buffer[0] = -1;
     EXPECT_FALSE(UartUnpackToCamera(buffer));
   }
 }
diff --git a/y2019/vision/global_calibration.cc b/y2019/vision/global_calibration.cc
index ac559b0..e2c4490 100644
--- a/y2019/vision/global_calibration.cc
+++ b/y2019/vision/global_calibration.cc
@@ -198,7 +198,7 @@
         const ::aos::vision::Vector<2> target_point = target_value[j];
 
         // Now build up the residual block.
-        auto ftor = [template_point, target_point, i](
+        auto ftor = [template_point, target_point](
             const double *const intrinsics, const double *const extrinsics,
             double *residual) {
           const IntrinsicParams intrinsic_params =