Skip to content

Commit

Permalink
Merge pull request #156 from microsoft/cpp23usage
Browse files Browse the repository at this point in the history
Simple C++23 functionality replacements
  • Loading branch information
abeltrano authored Feb 20, 2024
2 parents 403f272 + 164886a commit 7cba9b6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 32 deletions.
45 changes: 22 additions & 23 deletions src/common/wifi/core/include/microsoft/net/wifi/Ieee80211.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
#include <cstdint>
#include <initializer_list>
#include <string>

#include <notstd/Utility.hxx>
#include <utility>

namespace Microsoft::Net::Wifi
{
Expand Down Expand Up @@ -205,27 +204,27 @@ enum class Ieee80211AkmSuite : uint32_t {
* only supports enums with values up to UINT16_MAX-1, and the AKM suite underlying type is uint32_t, so cannot be used.
*/
constexpr std::initializer_list<uint32_t> AllIeee80211Akms{
notstd::to_underlying(Ieee80211AkmSuite::Reserved0),
notstd::to_underlying(Ieee80211AkmSuite::Ieee8021x),
notstd::to_underlying(Ieee80211AkmSuite::Psk),
notstd::to_underlying(Ieee80211AkmSuite::Ft8021x),
notstd::to_underlying(Ieee80211AkmSuite::FtPsk),
notstd::to_underlying(Ieee80211AkmSuite::Ieee8021xSha256),
notstd::to_underlying(Ieee80211AkmSuite::PskSha256),
notstd::to_underlying(Ieee80211AkmSuite::Tdls),
notstd::to_underlying(Ieee80211AkmSuite::Sae),
notstd::to_underlying(Ieee80211AkmSuite::FtSae),
notstd::to_underlying(Ieee80211AkmSuite::ApPeerKey),
notstd::to_underlying(Ieee80211AkmSuite::Ieee8021xSuiteB),
notstd::to_underlying(Ieee80211AkmSuite::Ieee8011xSuiteB192),
notstd::to_underlying(Ieee80211AkmSuite::Ft8021xSha384),
notstd::to_underlying(Ieee80211AkmSuite::FilsSha256),
notstd::to_underlying(Ieee80211AkmSuite::FilsSha384),
notstd::to_underlying(Ieee80211AkmSuite::FtFilsSha256),
notstd::to_underlying(Ieee80211AkmSuite::FtFilsSha384),
notstd::to_underlying(Ieee80211AkmSuite::Owe),
notstd::to_underlying(Ieee80211AkmSuite::FtPskSha384),
notstd::to_underlying(Ieee80211AkmSuite::PskSha384),
std::to_underlying(Ieee80211AkmSuite::Reserved0),
std::to_underlying(Ieee80211AkmSuite::Ieee8021x),
std::to_underlying(Ieee80211AkmSuite::Psk),
std::to_underlying(Ieee80211AkmSuite::Ft8021x),
std::to_underlying(Ieee80211AkmSuite::FtPsk),
std::to_underlying(Ieee80211AkmSuite::Ieee8021xSha256),
std::to_underlying(Ieee80211AkmSuite::PskSha256),
std::to_underlying(Ieee80211AkmSuite::Tdls),
std::to_underlying(Ieee80211AkmSuite::Sae),
std::to_underlying(Ieee80211AkmSuite::FtSae),
std::to_underlying(Ieee80211AkmSuite::ApPeerKey),
std::to_underlying(Ieee80211AkmSuite::Ieee8021xSuiteB),
std::to_underlying(Ieee80211AkmSuite::Ieee8011xSuiteB192),
std::to_underlying(Ieee80211AkmSuite::Ft8021xSha384),
std::to_underlying(Ieee80211AkmSuite::FilsSha256),
std::to_underlying(Ieee80211AkmSuite::FilsSha384),
std::to_underlying(Ieee80211AkmSuite::FtFilsSha256),
std::to_underlying(Ieee80211AkmSuite::FtFilsSha384),
std::to_underlying(Ieee80211AkmSuite::Owe),
std::to_underlying(Ieee80211AkmSuite::FtPskSha384),
std::to_underlying(Ieee80211AkmSuite::PskSha384),
};

/**
Expand Down
9 changes: 4 additions & 5 deletions src/linux/server/Main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <microsoft/net/wifi/AccessPointDiscoveryAgentOperationsNetlink.hxx>
#include <microsoft/net/wifi/AccessPointLinux.hxx>
#include <microsoft/net/wifi/AccessPointManager.hxx>
#include <notstd/Utility.hxx>
#include <plog/Appenders/ColorConsoleAppender.h>
#include <plog/Appenders/RollingFileAppender.h>
#include <plog/Formatters/MessageOnlyFormatter.h>
Expand Down Expand Up @@ -44,11 +43,11 @@ main(int argc, char *argv[])
const auto logSeverity = logging::LogVerbosityToPlogSeverity(configuration.LogVerbosity);

// Configure logging, appending all loggers to the default instance.
plog::init<notstd::to_underlying(LogInstanceId::Console)>(logSeverity, &colorConsoleAppender);
plog::init(logSeverity).addAppender(plog::get<notstd::to_underlying(LogInstanceId::Console)>());
plog::init<std::to_underlying(LogInstanceId::Console)>(logSeverity, &colorConsoleAppender);
plog::init(logSeverity).addAppender(plog::get<std::to_underlying(LogInstanceId::Console)>());
if (configuration.EnableFileLogging) {
plog::init<notstd::to_underlying(LogInstanceId::File)>(logSeverity, &rollingFileAppender);
plog::init(logSeverity).addAppender(plog::get<notstd::to_underlying(LogInstanceId::File)>());
plog::init<std::to_underlying(LogInstanceId::File)>(logSeverity, &rollingFileAppender);
plog::init(logSeverity).addAppender(plog::get<std::to_underlying(LogInstanceId::File)>());
}

// Create an access point manager and discovery agent.
Expand Down
4 changes: 2 additions & 2 deletions src/linux/wpa-controller/WpaResponseParser.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ WpaResponseParser::GetResponsePayload() const noexcept
bool
WpaResponseParser::TryParseProperties()
{
// Convert a range to a string-view for pre-C++23 where std::string_view doesn't have a range constructor.
// Convert a range to a string-view.
constexpr auto toStringView = [](auto&& sv) {
return std::string_view{ std::data(sv), std::size(sv) };
return std::string_view(sv);
};
// Convert a key-value pair to its key.
constexpr auto toKey = [](auto&& keyValuePair) {
Expand Down
4 changes: 2 additions & 2 deletions src/linux/wpa-controller/include/Wpa/WpaKeyValuePair.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

#include <optional>
#include <string_view>
#include <utility>

#include <Wpa/ProtocolWpa.hxx>
#include <notstd/Utility.hxx>

namespace Wpa
{
Expand Down Expand Up @@ -41,7 +41,7 @@ struct WpaKeyValuePair
*/
constexpr WpaKeyValuePair(std::string_view key, WpaValuePresence presence, bool isIndexed = false) :
Key(key),
IsRequired(notstd::to_underlying(presence)),
IsRequired(std::to_underlying(presence)),
IsIndexed(isIndexed)
{
}
Expand Down

0 comments on commit 7cba9b6

Please sign in to comment.